Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#28166 closed Bug (fixed)

Model _state.db for an inherited object is not correctly populated to parent object

Reported by: wckao Owned by: nobody
Component: Database layer (models, ORM) Version: 1.11
Severity: Release blocker Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

For the following models:

class ModelA(models.Model):
    name = models.CharField(max_length=10)

class ModelB(ModelA):
    is_active = models.BooleanField()

On shell:

b = ModelB.objects.create(name="test", is_active=True)
b.id = None
b.pk = None
b.save()
print(b._state.db, b.modela_ptr._state.db)

On 1.10, it shows "default default",
but after upgrading from 1.10 to 1.11, it shows "default None"

Change History (6)

comment:1 by wckao, 8 years ago

Summary: Model _state.db for an inherited object is not correctly populatedModel _state.db for an inherited object is not correctly populated to parent object

comment:2 by Tim Graham, 8 years ago

Component: UncategorizedDatabase layer (models, ORM)
Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

comment:3 by Simon Charette, 8 years ago

It should only be a matter of storing the result of rel_model in a temporary variable to assign _state.db = instance._state.db to it before returning in ForwardOneToOneDescriptor. get_object().

comment:4 by Tim Graham, 8 years ago

Has patch: set

comment:5 by Tim Graham <timograham@…>, 8 years ago

Resolution: fixed
Status: newclosed

In 584e10c7:

Fixed #28166 -- Fixed Model._state.db on MTI parent model after saving child model.

Regression in 38575b007a722d6af510ea46d46393a4cda9ca29.

comment:6 by Tim Graham <timograham@…>, 8 years ago

In f3217ab5:

[1.11.x] Fixed #28166 -- Fixed Model._state.db on MTI parent model after saving child model.

Regression in 38575b007a722d6af510ea46d46393a4cda9ca29.

Backport of 584e10c76edcd3a33765a52c5cde0096a3ce7dbc from master

Note: See TracTickets for help on using tickets.
Back to Top