Opened 5 years ago

Closed 5 years ago

#31219 closed Bug (fixed)

Raising error about protected related objects can crash.

Reported by: Matthias Kestenholz Owned by: Matthias Kestenholz
Component: Database layer (models, ORM) Version: dev
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 (last modified by Matthias Kestenholz)

======================================================================
ERROR: test_protect_via (delete.tests.OnDeleteTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3.6/unittest/case.py", line 59, in testPartExecutor
    yield
  File "/usr/lib/python3.6/unittest/case.py", line 605, in run
    testMethod()
  File "/home/matthias/Projects/django/tests/delete/tests.py", line 99, in test_protect_via
    p.delete()
  File "/home/matthias/Projects/django/django/db/models/base.py", line 941, in delete
    collector.collect([self], keep_parents=keep_parents)
  File "/home/matthias/Projects/django/django/db/models/deletion.py", line 300, in collect
    error.protected_objects[0].__class__.__name__,
TypeError: 'itertools.chain' object is not subscriptable

Pull request follows.

(By the way, this came up while testing https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/django-developers/WmgqJnQ6ioE/b52uACoPAgAJ / the JSONField GSoC pull request. Apart from this crash everything worked fine!)

Change History (7)

comment:1 by Matthias Kestenholz, 5 years ago

comment:2 by Matthias Kestenholz, 5 years ago

Description: modified (diff)

comment:3 by Simon Charette, 5 years ago

Triage Stage: UnreviewedAccepted

comment:4 by Mariusz Felisiak, 5 years ago

Has patch: set
Owner: changed from nobody to Matthias Kestenholz
Severity: NormalRelease blocker
Status: newassigned
Summary: PROTECT may crash in some situationsRaising error about protected fields can crash.

comment:5 by Mariusz Felisiak, 5 years ago

Summary: Raising error about protected fields can crash.Raising error about protected related objects can crash.

Thanks for this report, it looks that something is also wrong in the error message.

Bumping to a release blocker (Django 3.1) because it's a regression in ab3cbd8b9a315911248227208630a020cedca08f.

We probably create a similar regression in 4ca5c565f4dc9e97845036e86416abc5cfde766c for restricted related objects. Can you check if they are also affected?

comment:6 by Matthias Kestenholz, 5 years ago

I added another commit on top (https://github.com/django/django/pull/12394/commits/42fb622f8895f59ff6ad76b761c1eb9b41fd9549) which tests the RESTRICT case.

The RESTRICT case shows a foreign key which actually exists, but it does not point at the P object yet but at the intermediate R object. It does not crash because there is no code accessing the first restricted object as is the case with protected objects.

comment:7 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

Resolution: fixed
Status: assignedclosed

In 4e8d8902:

Fixed #31219 -- Fixed object deletion crash for nested protected related objects.

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