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
Fix quotation marks being included in search path #829
Conversation
Example where search path is quoted: ``` db=# SET search_path = 'country_BD'; SET farm2go=# SHOW search_path; search_path -------------- "country_BD" (1 row) ```
Codecov ReportBase: 87.21% // Head: 87.21% // No change to project coverage 👍
Additional details and impacted files@@ Coverage Diff @@
## master #829 +/- ##
=======================================
Coverage 87.21% 87.21%
=======================================
Files 52 52
Lines 2363 2363
=======================================
Hits 2061 2061
Misses 302 302
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
@atodorov are you happy with this? |
The change itself looks good but given the importance it needs a test scenario. I can look into testing over the weekend if @libcthorne doesn't beat me to it first. |
Feel free to take this on, otherwise I can look in the coming weeks! |
…o-tenants#829 according to the description in django-tenants#829 Postgres will double quote schema names which contain underscores.
now the test uses schema names with underscores which should trigger the failure
…o-tenants#829 according to the description in django-tenants#829 Postgres will double quote schema names which contain underscores.
now the test uses schema names with underscores which should trigger the failure
This reverts commit 5f25990. The reported issue in django-tenants#829 is reproducible on Postgres 11 but not on later versions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[PostgreSQL version: 11.1]
During my tests in #921 I've discovered that later versions also add the double quotes. For example:
2023-04-19T16:00:42.9978058Z ***** DEBUG: raw data from Postgres: ('"tenant`1", public',)
2023-04-19T16:00:43.0302627Z ***** DEBUG: raw data from Postgres: ('"tenant-2", public',)
Schema names containing underscores are wrapped in quotation marks by postgres when running
FTR that seems true for country_BD
, maybe b/c it contains upper-case letters, but didn't hold true for schema names such as tenant_1
and tenant_2
that I tried with.
Regardless of the facts above I can't reproduce a failure in #921, even without this patch.
If the logs are inspected we can see that there are search paths which are quoted with double quotes, raw data from Postgres. These are usually schema names containing special characters.
There's also an explicit test called test_switching_search_path
which switches between 2 tenants and asserts on the number of objects inside of them (different numbers).
@libcthorne can you provide some more information about the reproducer?
At the time when you opened this PR did you use a version of django-tenants with #693 applied, (v3.4.0 or later)?
Which Python version did you have installed ?
…o-tenants#829 according to the description in django-tenants#829 Postgres will double quote schema names which contain underscores. More precisely names which contain underscores and a mixture of lower case and upper case letters will be quoted!
now the test uses schema names which will be double quoted by Postgres
This reverts commit 5f25990. The reported issue in django-tenants#829 is reproducible on Postgres 11 but not on later versions
Unfortunately I'm failing to update the test suite in a way that would use version 3.4.5 to verify the reproducer. It has to do with how we setup the environment (python setup.py develop). @libcthorne does the failure happen for you with the latest release of django-tenants ? I'm trying to figure out if there's more to the reproducer than meets the eye. @tomturner I'm on the fence about this PR. On one hand it looks sane and obviously solves a problem. On the other hand unmodified django-tenants seems to work fine and not be able to trigger the original issue so why bother changing. WDYT ? |
I confirm the issue is still present on the latest django-tenants (3.4.8) and and Python 3.11. The context is that when using pytest with --create-db, the database setup fails as it tries to create the same table twice. At some point there's a table lookup to see if the table already exists before attempting creation but it gets it wrong due to the incorrect search path.
I am working around it by manually applying the patch in this PR using a custom backend:
|
according to the description in #829 Postgres will double quote schema names which contain underscores. More precisely names which contain underscores and a mixture of lower case and upper case letters will be quoted!
now the test uses schema names which will be double quoted by Postgres
[PostgreSQL version: 11.1]
Schema names containing underscores are wrapped in quotation marks by postgres when running
SHOW search_path
:Without the underscore, the quotation marks are not present:
As a result, when a schema name contains an underscore, the search path restoration logic ends up adding quotes each time and table lookups stop working:
This PR extends #693 to fix the issue.