Make sure get_dsn_parameters is an actual function#2441
Conversation
Some non-standard DB backends have their own __getattr__, which renders our check for attributes useless.
get_dsn_params is an actual functionget_dsn_parameters is an actual function
antonpirker
left a comment
There was a problem hiding this comment.
Just one question about coroutines (i am soo messed up by async python...)
| and hasattr(cursor_or_db.connection, "get_dsn_parameters") | ||
| else db.get_connection_params() | ||
| ) | ||
| and inspect.isfunction(cursor_or_db.connection.get_dsn_parameters) |
There was a problem hiding this comment.
is there a world where this could be a coroutine?
There was a problem hiding this comment.
Shouldn't be, that's a psycopg2 sync function.
Btw, sidenote to this. Something I learned while looking at this is that newer Django uses psycopg (i.e., psycopg 3) instead of psycopg2. psycopg doesn't have this function. So this condition will always fall back to using get_connection_params instead. This is relevant because we added the get_dsn_parameters part to bypass calling get_connection_params for postgres.
There was a problem hiding this comment.
My hunch was correct 😞 Reopened the original issue: #2303
Some non-standard Django DB connectors (djongo/pymongo) define their own
__getattr__, which renders our check for attributes trivially True, only to explode when actually trying to call the attribute as a function.Patch tested with
Closes #2438