[Django] #25715: refresh_from_db fails to update null'ed ForeignKeys

12 views
Skip to first unread message

Django

unread,
Nov 8, 2015, 11:31:06 PM11/8/15
to django-...@googlegroups.com
#25715: refresh_from_db fails to update null'ed ForeignKeys
-------------------------------+--------------------
Reporter: joshkel | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
I have User and Org models, with User having a ForeignKey to Org:

{{{#!python
org = models.ForeignKey('Org', null=True, blank=True,
on_delete=models.SET_NULL)
}}}

If I delete an Org instance then refresh the User instance, then
user.org_id is cleared as expected, but user.org still references the
deleted instance:

{{{#!python
org = create_org()
user = create_user(org)
org.delete()

user.refresh_from_db()
self.assertIsNone(user.org_id) # Works!
self.assertIsNone(user.org) # Fails!
}}}

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

Django

unread,
Nov 10, 2015, 10:04:26 AM11/10/15
to django-...@googlegroups.com
#25715: refresh_from_db fails to update null'ed ForeignKeys
-------------------------------------+-------------------------------------
Reporter: joshkel | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* severity: Normal => Release blocker
* needs_better_patch: => 0
* component: Uncategorized => Database layer (models, ORM)
* needs_tests: => 0
* needs_docs: => 0
* type: Uncategorized => Bug
* stage: Unreviewed => Accepted


Comment:

`on_delete=models.SET_NULL` in the `ForeignKey` seems to be the important
part of reproducing this.

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

Django

unread,
Nov 12, 2015, 11:32:22 PM11/12/15
to django-...@googlegroups.com
#25715: refresh_from_db fails to update null'ed ForeignKeys
-------------------------------------+-------------------------------------
Reporter: joshkel | Owner:
| andersonresende
Type: Bug | Status: assigned

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

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

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


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

Django

unread,
Nov 20, 2015, 10:54:19 AM11/20/15
to django-...@googlegroups.com
#25715: refresh_from_db fails to update null'ed ForeignKeys
-------------------------------------+-------------------------------------
Reporter: joshkel | Owner: timgraham

Type: Bug | Status: assigned
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Release blocker | 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 timgraham):

* owner: andersonresende => timgraham
* has_patch: 0 => 1


Comment:

@andersonresende, sorry to take this one if you made any progress on it,
but I wanted to make sure it's fixed for the next 1.8.x release. Feel free
to review my patch if you can.

[https://github.com/django/django/pull/5694 PR]

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

Django

unread,
Nov 21, 2015, 3:47:44 AM11/21/15
to django-...@googlegroups.com
#25715: refresh_from_db fails to update null'ed ForeignKeys
-------------------------------------+-------------------------------------
Reporter: joshkel | Owner: timgraham
Type: Bug | Status: assigned
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* stage: Accepted => Ready for checkin


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

Django

unread,
Nov 21, 2015, 11:30:22 AM11/21/15
to django-...@googlegroups.com
#25715: refresh_from_db fails to update null'ed ForeignKeys
-------------------------------------+-------------------------------------
Reporter: joshkel | Owner: timgraham
Type: Bug | Status: closed

Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Release blocker | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"54e2e688e1cfbdb37dfa5dd3b3ffdf2af12b4423" 54e2e68]:
{{{
#!CommitTicketReference repository=""
revision="54e2e688e1cfbdb37dfa5dd3b3ffdf2af12b4423"
Fixed #25715 -- Fixed Model.refresh_from_db() with ForeignKey
w/on_delete=SET_NULL.
}}}

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

Django

unread,
Nov 21, 2015, 11:57:04 AM11/21/15
to django-...@googlegroups.com
#25715: refresh_from_db fails to update null'ed ForeignKeys
-------------------------------------+-------------------------------------
Reporter: joshkel | Owner: timgraham
Type: Bug | Status: closed
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"2179e5a2bcf42fc902eff4d586756665b9ac8f42" 2179e5a]:
{{{
#!CommitTicketReference repository=""
revision="2179e5a2bcf42fc902eff4d586756665b9ac8f42"
[1.8.x] Fixed #25715 -- Fixed Model.refresh_from_db() with ForeignKey
w/on_delete=SET_NULL.

Backport of 54e2e688e1cfbdb37dfa5dd3b3ffdf2af12b4423 from master
}}}

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

Django

unread,
Nov 21, 2015, 11:57:10 AM11/21/15
to django-...@googlegroups.com
#25715: refresh_from_db fails to update null'ed ForeignKeys
-------------------------------------+-------------------------------------
Reporter: joshkel | Owner: timgraham
Type: Bug | Status: closed
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"8727dc8e951d0c3f4afc9cc2a5159fb651e5535c" 8727dc8]:
{{{
#!CommitTicketReference repository=""
revision="8727dc8e951d0c3f4afc9cc2a5159fb651e5535c"
[1.9.x] Fixed #25715 -- Fixed Model.refresh_from_db() with ForeignKey
w/on_delete=SET_NULL.

Backport of 54e2e688e1cfbdb37dfa5dd3b3ffdf2af12b4423 from master
}}}

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

Reply all
Reply to author
Forward
0 new messages