Opened 10 years ago
Last modified 15 months ago
#23318 new New feature
Management command dbshell does not use DATABASE[...]['OPTIONS'] to set env PGOPTIONS
Reported by: | benjaoming | Owned by: | |
---|---|---|---|
Component: | Core (Management commands) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | tomi.kyostila@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | yes |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
I am trying to make use of a different "search_path" by use of settings.DATABASE[...]['OPTIONS'] = '-c search_path=my_other_schema,public'
-- however, since they are not passed, python manage.py dbshell --database=MY_OTHER_DATABASE_CONNECTION
will yield an unexpected result.
The problem is that the shell env variable PGOPTIONS="-c search_path=MY_SEARCH_PATH_CONF" is not set.
I am using it for the purpose of having multiple south_migrationhistory tables, one for every database connection. They should have been populated by:
python manage.py sqlall south | python manage.py dbshell --database=DBNAME
Current work-around:
python manage.py sqlall south | PGOPTIONS="-c search_path=NAME_OF_MY_SCHEMA" python manage.py dbshell --database=DBNAME
I am not sure how 1.7 will handle migration histories when populating different database connections and auto-selecting them using routers. But at least having the above to work would be nice, because it makes it easy to manually pipe around the SQL statements to different DB connections.
Also in more severe cases, not having the connection options passed to dbshell might yield other unexpected results!?
This might be of interest to other db backends, but please limit the issue here to only postgres, as it's perfectly simple to copy in the contents of OPTIONS to the env variable PGOPTIONS.
Change History (12)
comment:1 by , 10 years ago
Component: | Database layer (models, ORM) → Core (Management commands) |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Bug → New feature |
comment:2 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 10 years ago
Easy pickings: | set |
---|---|
Has patch: | set |
Version: | 1.7-rc-2 → master |
comment:4 by , 10 years ago
Easy pickings: | unset |
---|---|
Patch needs improvement: | set |
I left comments for improvement on the PR. Please uncheck "Patch needs improvement" when you update it, thanks.
comment:5 by , 10 years ago
Cc: | added |
---|
follow-up: 8 comment:7 by , 5 years ago
The implementation differs from initial implementation because OPTIONS may be used to set many connection configurations of psycopg2 other than options or PGOPTIONS.
follow-up: 9 comment:8 by , 5 years ago
Replying to Dulmandakh:
.... may be used to set many connection configurations of psycopg2 other than options or PGOPTIONS.
I'm not sure what does it mean? You want to pass options
to the PGOPTIONS
so how it can support sth else? The list of all available options can be found in the PostgreSQL docs. Also I'm not sure (as pointed by Tim) if passing all possible options is safe.
comment:9 by , 5 years ago
Replying to felixxm:
Replying to Dulmandakh:
.... may be used to set many connection configurations of psycopg2 other than options or PGOPTIONS.
I'm not sure what does it mean? You want to pass
options
to thePGOPTIONS
so how it can support sth else? The list of all available options can be found in the PostgreSQL docs. Also I'm not sure (as pointed by Tim) if passing all possible options is safe.
IIRC, OPTIONS passed to psycopg2.connect method directly as a part of kwargs, so it might be best to not interfere with it. Also we cannot determine which options are safe or not, so it might be best to leave it a web developer to decide.
comment:10 by , 4 years ago
Owner: | changed from | to
---|---|
Patch needs improvement: | unset |
Improvement flag was set on previous patch, so unsetting for new patch and assigning to PR author.
comment:11 by , 4 years ago
Needs documentation: | set |
---|---|
Patch needs improvement: | set |
comment:12 by , 15 months ago
Owner: | removed |
---|---|
Status: | assigned → new |
It looks like a reasonable request, and we recently enhanced the options that dbshell accepts when using MySQL (#22646).