[Django] #27614: Storing the DB used in the state before calling `_save_table`

11 views
Skip to first unread message

Django

unread,
Dec 18, 2016, 2:50:16 PM12/18/16
to django-...@googlegroups.com
#27614: Storing the DB used in the state before calling `_save_table`
-------------------------------------+-------------------------------------
Reporter: Joseph | Owner: nobody
Kahn |
Type: | Status: new
Uncategorized |
Component: Database | Version: 1.10
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
I was trying to figure out why when calling `.using` before `.create` the
`self._state.db` was not available. I happen to want the result of that to
use in the `pk` value, so right now I have to re fetch that information.
As it turns out, the cause can be narrowed down to a single line. However,
I'm not sure if it was ordered that way for a reason but here:
https://github.com/django/django/blob/d2a26c1a90e837777dabdf3d67ceec4d2a70fb86/django/db/models/base.py#L831-L836

Since not every function call gets the `using` param passed to it, but
most get the `instance` like when it wants to get a pk value prior to
saving.

I was wondering if it's possible to move that `self._state.db = using` up.

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

Django

unread,
Dec 19, 2016, 7:53:42 AM12/19/16
to django-...@googlegroups.com
#27614: Storing the DB used in the state before calling `_save_table`
-------------------------------------+-------------------------------------
Reporter: Joseph Kahn | Owner: nobody
Type: Uncategorized | Status: new
Component: Database layer | Version: 1.10
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

Does the test suite pass with the change?

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

Django

unread,
Dec 20, 2016, 9:04:27 AM12/20/16
to django-...@googlegroups.com
#27614: Storing the DB used in the state before calling `_save_table`
-------------------------------------+-------------------------------------
Reporter: Joseph Kahn | Owner: nobody
Type: Uncategorized | Status: closed

Component: Database layer | Version: 1.10
(models, ORM) |
Severity: Normal | Resolution: needsinfo
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* status: new => closed
* resolution: => needsinfo


Comment:

The proposed change doesn't seem to work, at least
`multiple_database.tests.RouterTestCase.test_deferred_models` fails. Feel
free to reopen if you have a working patch.

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

Django

unread,
Jan 12, 2017, 3:07:55 PM1/12/17
to django-...@googlegroups.com
#27614: Storing the DB used in the state before calling `_save_table`
-------------------------------------+-------------------------------------
Reporter: Joseph Kahn | Owner: nobody
Type: Uncategorized | Status: closed
Component: Database layer | Version: 1.10
(models, ORM) |
Severity: Normal | Resolution: needsinfo
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Joseph Kahn):

I created a PR with a change that doesn't break that test but fixes it for
a lot of the edge cases I run into with multiple databases.

https://github.com/django/django/pull/7841

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

Django

unread,
Jan 12, 2017, 3:08:08 PM1/12/17
to django-...@googlegroups.com
#27614: Storing the DB used in the state before calling `_save_table`
-------------------------------------+-------------------------------------
Reporter: Joseph Kahn | Owner: nobody
Type: Uncategorized | Status: new

Component: Database layer | Version: 1.10
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Joseph Kahn):

* status: closed => new
* resolution: needsinfo =>


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

Django

unread,
Jan 20, 2017, 7:17:07 PM1/20/17
to django-...@googlegroups.com
#27614: Store the DB used in the state before calling Model._save_table()

-------------------------------------+-------------------------------------
Reporter: Joseph Kahn | Owner: nobody
Type: | Status: new
Cleanup/optimization |

Component: Database layer | Version: 1.10
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

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

* has_patch: 0 => 1
* stage: Unreviewed => Accepted
* type: Uncategorized => Cleanup/optimization
* needs_tests: 0 => 1


Comment:

Tentatively accepting, although I haven't analyzed this in detail. Perhaps
adding a test to the pull request will clarify the use case.

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

Django

unread,
Apr 7, 2017, 6:10:16 AM4/7/17
to django-...@googlegroups.com
#27614: Store the DB used in the state before calling Model._save_table()
-------------------------------------+-------------------------------------
Reporter: Joseph Kahn | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: 1.10
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ingo Klöcker):

* has_patch: 1 => 0


Comment:

The pull request has been withdrawn.

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

Django

unread,
Nov 7, 2020, 10:48:17 AM11/7/20
to django-...@googlegroups.com
#27614: Store the DB used in the state before calling Model._save_table()
-------------------------------------+-------------------------------------
Reporter: Joseph Kahn | Owner: Paul
Type: | Cameron
Cleanup/optimization | Status: assigned

Component: Database layer | Version: 1.10
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

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

* owner: nobody => Paul Cameron
* status: new => assigned


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

Reply all
Reply to author
Forward
0 new messages