Opened 11 months ago

Closed 11 months ago

Last modified 11 months ago

#35024 closed Bug (fixed)

Creating model objects crashes on fields with database converters when RETURNING is not supported.

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

Description

Creating model objects crashes on fields with database converters when RETURNING is not supported. For example

class GeneratedBooleanFieldModel(Model):
    value = IntegerField(null=True)
    has_value = GeneratedField(
        expression=Q(value__isnull=False),
        output_field=BooleanField(),
        db_persist=False,
    )

crashes with:

  File "/home/jenkins/workspace/pull-requests-focal/database/spatialite/label/focal-pr/python/python3.10/django/db/models/query.py", line 1845, in _insert
    return query.get_compiler(using=using).execute_sql(returning_fields)
  File "/home/jenkins/workspace/pull-requests-focal/database/spatialite/label/focal-pr/python/python3.10/django/db/models/sql/compiler.py", line 1853, in execute_sql
    rows = list(self.apply_converters(rows, converters))
  File "/home/jenkins/workspace/pull-requests-focal/database/spatialite/label/focal-pr/python/python3.10/django/db/models/sql/compiler.py", line 1500, in apply_converters
    value = row[pos]
IndexError: list index out of range

This is a long standing issue, however it caused a crash of GeneratedField for all output fields that have backend-specific converters when RETURNING clause is not supported (MySQL and SQLite < 3.35). We should exacerbate severity to a release blocker.

Regression in d9de74141e8a920940f1b91ed0a3ccb835b55729.

Change History (5)

comment:1 by Mariusz Felisiak, 11 months ago

comment:2 by Mariusz Felisiak, 11 months ago

Has patch: set

comment:3 by Simon Charette, 11 months ago

Triage Stage: UnreviewedAccepted

comment:4 by GitHub <noreply@…>, 11 months ago

Resolution: fixed
Status: assignedclosed

In 5b3b791:

Fixed #35024 -- Fixed model instance creation crash on GeneratedField.output_field with backend converters.

Regression in d9de74141e8a920940f1b91ed0a3ccb835b55729.

This is a long standing issue, however it caused a crash of
GeneratedFields for all output fields that have backend-specific
converters when the RETURNING clause is not supported
(MySQL and SQLite < 3.35).
That's why severity was exacerbated.

comment:5 by Mariusz Felisiak <felisiak.mariusz@…>, 11 months ago

In 415a08a5:

[5.0.x] Fixed #35024 -- Fixed model instance creation crash on GeneratedField.output_field with backend converters.

Regression in d9de74141e8a920940f1b91ed0a3ccb835b55729.

This is a long standing issue, however it caused a crash of
GeneratedFields for all output fields that have backend-specific
converters when the RETURNING clause is not supported
(MySQL and SQLite < 3.35).
That's why severity was exacerbated.
Backport of 5b3b791e9046461901df3898be8544e14d91b931 from main

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