Opened 15 months ago

Closed 15 months ago

Last modified 15 months 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 Changed 15 months ago by wckao

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 Changed 15 months ago by Tim Graham

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

comment:3 Changed 15 months ago by Simon Charette

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 Changed 15 months ago by Tim Graham

Has patch: set

comment:5 Changed 15 months ago by Tim Graham <timograham@…>

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 Changed 15 months ago by Tim Graham <timograham@…>

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