[Django] #23318: Management command dbshell does not use DATABASE[...]['OPTIONS'] to set env PGOPTIONS

58 views
Skip to first unread message

Django

unread,
Aug 19, 2014, 11:51:34 AM8/19/14
to django-...@googlegroups.com
#23318: Management command dbshell does not use DATABASE[...]['OPTIONS'] to set env
PGOPTIONS
----------------------------------------------+----------------------
Reporter: benjaoming | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.7-rc-2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+----------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/23318>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 27, 2014, 9:12:11 AM8/27/14
to django-...@googlegroups.com
#23318: Management command dbshell does not use DATABASE[...]['OPTIONS'] to set env
PGOPTIONS
-------------------------------------+-------------------------------------
Reporter: benjaoming | Owner: nobody
Type: New feature | Status: new
Component: Core (Management | Version: 1.7-rc-2
commands) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: => 0
* component: Database layer (models, ORM) => Core (Management commands)
* needs_tests: => 0
* needs_docs: => 0
* type: Bug => New feature
* stage: Unreviewed => Accepted


Comment:

It looks like a reasonable request, and we recently enhanced the options
that dbshell accepts when using MySQL (#22646).

--
Ticket URL: <https://code.djangoproject.com/ticket/23318#comment:1>

Django

unread,
Sep 5, 2014, 4:40:37 PM9/5/14
to django-...@googlegroups.com
#23318: Management command dbshell does not use DATABASE[...]['OPTIONS'] to set env
PGOPTIONS
-------------------------------------+-------------------------------------
Reporter: benjaoming | Owner: fcurella
Type: New feature | Status: assigned

Component: Core (Management | Version: 1.7-rc-2
commands) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by fcurella):

* owner: nobody => fcurella
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/23318#comment:2>

Django

unread,
Sep 5, 2014, 5:15:53 PM9/5/14
to django-...@googlegroups.com
#23318: Management command dbshell does not use DATABASE[...]['OPTIONS'] to set env
PGOPTIONS
-------------------------------------+-------------------------------------
Reporter: benjaoming | Owner: fcurella
Type: New feature | Status: assigned
Component: Core (Management | Version: master

commands) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0

Needs tests: 0 | UI/UX: 0
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by fcurella):

* has_patch: 0 => 1
* version: 1.7-rc-2 => master
* easy: 0 => 1


Comment:

PR up at https://github.com/django/django/pull/3168

--
Ticket URL: <https://code.djangoproject.com/ticket/23318#comment:3>

Django

unread,
Sep 6, 2014, 12:49:26 PM9/6/14
to django-...@googlegroups.com
#23318: Management command dbshell does not use DATABASE[...]['OPTIONS'] to set env
PGOPTIONS
-------------------------------------+-------------------------------------
Reporter: benjaoming | Owner: fcurella
Type: New feature | Status: assigned
Component: Core (Management | Version: master
commands) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 1

Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: 0 => 1
* easy: 1 => 0


Comment:

I left comments for improvement on the PR. Please uncheck "Patch needs
improvement" when you update it, thanks.

--
Ticket URL: <https://code.djangoproject.com/ticket/23318#comment:4>

Django

unread,
Apr 12, 2015, 2:58:28 PM4/12/15
to django-...@googlegroups.com
#23318: Management command dbshell does not use DATABASE[...]['OPTIONS'] to set env
PGOPTIONS
-------------------------------------+-------------------------------------
Reporter: benjaoming | Owner: fcurella
Type: New feature | Status: assigned
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by tomikyos):

* cc: tomi.kyostila@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/23318#comment:5>

Django

unread,
Apr 14, 2020, 8:39:57 PM4/14/20
to django-...@googlegroups.com
#23318: Management command dbshell does not use DATABASE[...]['OPTIONS'] to set env
PGOPTIONS
-------------------------------------+-------------------------------------
Reporter: benjaoming | Owner: Flavio
| Curella

Type: New feature | Status: assigned
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Dulmandakh):

PR https://github.com/django/django/pull/12715

--
Ticket URL: <https://code.djangoproject.com/ticket/23318#comment:6>

Django

unread,
Apr 14, 2020, 8:48:54 PM4/14/20
to django-...@googlegroups.com
#23318: Management command dbshell does not use DATABASE[...]['OPTIONS'] to set env
PGOPTIONS
-------------------------------------+-------------------------------------
Reporter: benjaoming | Owner: Flavio
| Curella
Type: New feature | Status: assigned
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Dulmandakh):

The implementation differs from initial implementation because OPTIONS may
be used to set many connection configurations of psycopg2 other than
**options** or PGOPTIONS.

--
Ticket URL: <https://code.djangoproject.com/ticket/23318#comment:7>

Django

unread,
Apr 15, 2020, 12:25:49 AM4/15/20
to django-...@googlegroups.com
#23318: Management command dbshell does not use DATABASE[...]['OPTIONS'] to set env
PGOPTIONS
-------------------------------------+-------------------------------------
Reporter: benjaoming | Owner: Flavio
| Curella
Type: New feature | Status: assigned
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by felixxm):

Replying to [comment:7 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 [https://www.postgresql.org/docs/10/runtime-
config.html the PostgreSQL docs]. Also I'm not sure
([https://github.com/django/django/pull/3168#issuecomment-55174417 as
pointed by Tim]) if passing all possible options is safe.

--
Ticket URL: <https://code.djangoproject.com/ticket/23318#comment:8>

Django

unread,
Apr 22, 2020, 9:01:08 PM4/22/20
to django-...@googlegroups.com
#23318: Management command dbshell does not use DATABASE[...]['OPTIONS'] to set env
PGOPTIONS
-------------------------------------+-------------------------------------
Reporter: benjaoming | Owner: Flavio
| Curella
Type: New feature | Status: assigned
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Dulmandakh):

Replying to [comment:8 felixxm]:


> Replying to [comment:7 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 [https://www.postgresql.org/docs/10/runtime-
config.html the PostgreSQL docs]. Also I'm not sure
([https://github.com/django/django/pull/3168#issuecomment-55174417 as
pointed by Tim]) if passing all possible options is safe.

IIRC, OPTIONS passed to
[https://www.psycopg.org/docs/module.html#psycopg2.connect
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/23318#comment:9>

Django

unread,
Oct 25, 2020, 8:08:28 AM10/25/20
to django-...@googlegroups.com
#23318: Management command dbshell does not use DATABASE[...]['OPTIONS'] to set env
PGOPTIONS
-------------------------------------+-------------------------------------
Reporter: benjaoming | Owner:
| Dulmandakh

Type: New feature | Status: assigned
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* owner: Flavio Curella => Dulmandakh
* needs_better_patch: 1 => 0


Comment:

Improvement flag was set on previous patch, so unsetting for new patch and
assigning to PR author.

--
Ticket URL: <https://code.djangoproject.com/ticket/23318#comment:10>

Django

unread,
Oct 28, 2020, 5:14:33 AM10/28/20
to django-...@googlegroups.com
#23318: Management command dbshell does not use DATABASE[...]['OPTIONS'] to set env
PGOPTIONS
-------------------------------------+-------------------------------------
Reporter: benjaoming | Owner:
| Dulmandakh
Type: New feature | Status: assigned
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 0 => 1

* needs_docs: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/23318#comment:11>

Django

unread,
Oct 12, 2023, 5:23:23 AM10/12/23
to django-...@googlegroups.com
#23318: Management command dbshell does not use DATABASE[...]['OPTIONS'] to set env
PGOPTIONS
-------------------------------------+-------------------------------------
Reporter: benjaoming | Owner: (none)

Type: New feature | Status: new
Component: Core (Management | Version: dev

commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* owner: Dulmandakh => (none)
* status: assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/23318#comment:12>

Reply all
Reply to author
Forward
0 new messages