Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure get_dsn_parameters is an actual function #2441

Merged
merged 11 commits into from
Oct 17, 2023
Merged

Conversation

sentrivana
Copy link
Contributor

@sentrivana sentrivana commented Oct 12, 2023

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

Django==4.1.12
djongo==1.3.6
pymongo==3.12.3

Closes #2438

Some non-standard DB backends have their own __getattr__,
which renders our check for attributes useless.
@sentrivana sentrivana changed the title Make sure get_dsn_params is an actual function Make sure get_dsn_parameters is an actual function Oct 12, 2023
@sentrivana sentrivana marked this pull request as ready for review October 12, 2023 12:44
@sentrivana sentrivana marked this pull request as draft October 12, 2023 12:50
@sentrivana sentrivana marked this pull request as ready for review October 12, 2023 14:22
Copy link
Member

@antonpirker antonpirker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a world where this could be a coroutine?

Copy link
Contributor Author

@sentrivana sentrivana Oct 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My hunch was correct 😞 Reopened the original issue: #2303

@sentrivana sentrivana merged commit 4d10edf into master Oct 17, 2023
283 of 284 checks passed
@sentrivana sentrivana deleted the ivana/fix-djongo branch October 17, 2023 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for djongo
2 participants