#35350 closed Bug (fixed)
Crash on write of new instance when using GeneratedField
Reported by: | Matt Hegarty | Owned by: | Sarah Boyce |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 5.0 |
Severity: | Release blocker | Keywords: | GeneratedField |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
We have an issue in django-import-export where imports of new instances fails when the model has a GeneratedField.
This occurs when an instance is being created which doesn't already exist in the database, which the docs imply is supported by GeneratedField:
A stored generated column is computed when it is written (inserted or updated)
The stack trace is attached.
Steps to reproduce:
- Clone this repo and use the 'issue-1779-generatedfield' branch.
- Create a venv
- Install the example app following the instructions here
- Navigate to "Books", click "Import", then select the attached sample.csv file.
- Click "Submit" and you will see the error.
- python 3.12
- django 5.0.3
Attachments (2)
Change History (9)
by , 8 months ago
Attachment: | sample.csv added |
---|
comment:1 by , 8 months ago
Description: | modified (diff) |
---|
comment:2 by , 8 months ago
This is similar to #35019 (fixed by 03af8fbd0f1cfc08edadda248cf5d3498e8ed2f7) but when dealing with instances that have a primary key assigned and force_insert
is not specified.
When this is the case Mode.save
will first attempt to perform an UPDATE
as it cannot know whether or not the row exists.
It seems that the non_pk
logic in _save_table
needs to be adapted to also needs to exclude deferred fields.
comment:3 by , 8 months ago
Severity: | Normal → Release blocker |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:4 by , 8 months ago
Has patch: | set |
---|---|
Owner: | changed from | to
Status: | new → assigned |
comment:5 by , 8 months ago
Triage Stage: | Accepted → Ready for checkin |
---|
sample csv for import