psycopg2 --> psycopg3 breaking change: python type for bytea data changed. #733
Replies: 1 comment
-
psycopg 3 has breaking changes in the interface and data adaptation rules. This is documented and it is not expected that your code working with psycopg2 works with psycopg 3. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
in psycopg2
bytea
data was returned as amemoryview
psycopg3 returns a
bytes
object.Its not clear why this should cause a breaking change, but in my use case, this django code fragment works with psycopg2.
The model has a
BinaryField
nameddata
. Here I fetch an instance and return it as aFileResponse
:A solution that works with either adapter - just wrap the data buffer in an iterable:
Not clear to me the nature of the breaking change, just that this code has been in production for ~5 years and broke when I upgraded.
I suspect this is something about the way django handles the data buffer (comments in
StreamingHttpResponse
do saystreaming_content
should be an iterable of bytestrings.`) , combined with something subtle about the difference in how it is being produced by the 2 adapters, but I don't have a coherent story yet.Hoping someone who understands this could explain in a way that would allow me to document this issue in either Django or psycopg docs (or, more likely, where I've gone wrong ;-). thanks.
Beta Was this translation helpful? Give feedback.
All reactions