[Django] #36839: Renaming of content types on RenameModel operations silently passes when duplicates are found

8 views
Skip to first unread message

Django

unread,
Dec 31, 2025, 3:42:07 PM (2 days ago) 12/31/25
to django-...@googlegroups.com
#36839: Renaming of content types on RenameModel operations silently passes when
duplicates are found
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Type: Bug
Status: new | Component:
| contrib.contenttypes
Version: | Severity: Normal
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
When renaming a model, the `migrate` command will inject operations to
rename content types. When a target content type already exists, the
operation just silently skips the update:
{{{#!py
content_type.model = new_model
try:
with transaction.atomic(using=db):
content_type.save(using=db, update_fields={"model"})
except IntegrityError:
# Gracefully fallback if a stale content type causes a
# conflict as remove_stale_contenttypes will take care of
# asking the user what should be done next.
content_type.model = old_model
}}}

The rationale for skipping was discussed
[https://github.com/django/django/pull/6612#issuecomment-219584224 here]:

> In this case I think the safe approach is simply to silently handle the
integrity error and let the update_contenttypes's post_migrate handler
prompt the user about what to do next.

But that `post_migrate` handler was later removed in
6a2af01452966d10155b720f4f5e7b09c7e3e419 in favor of a management command
that can be run on demand, meaning the pass is now silent again, AFAICT.

I don't think the silent pass is desired. I can add more details if this
isn't enough context, but I think it's worth an initial investigation.
--
Ticket URL: <https://code.djangoproject.com/ticket/36839>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 1, 2026, 7:23:27 PM (20 hours ago) Jan 1
to django-...@googlegroups.com
#36839: Renaming of content types on RenameModel operations silently passes when
duplicates are found
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: (none)
Type: Bug | Status: new
Component: | Version:
contrib.contenttypes |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by mag123c):

I looked into this issue and traced the behavior in
`django/contrib/contenttypes/management/__init__.py`.

When `IntegrityError` is caught during the rename (lines 29-33), the code
silently reverts to the old model name. The comment mentions
`remove_stale_contenttypes` will handle it, but as noted, this is now an
optional management command - users have no way of knowing the rename
failed.

Possible approaches:
1. Emit a warning via `warnings.warn()` when the conflict occurs
2. Log at WARNING level so it appears in server logs
3. Raise an exception (though this may be too disruptive)

I'm curious whether the silent behavior was intentional for backwards
compatibility, or if surfacing this to users would be welcome.
--
Ticket URL: <https://code.djangoproject.com/ticket/36839#comment:1>

Django

unread,
Jan 1, 2026, 8:11:18 PM (20 hours ago) Jan 1
to django-...@googlegroups.com
#36839: Renaming of content types on RenameModel operations silently passes when
duplicates are found
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: (none)
Type: Bug | Status: new
Component: | Version:
contrib.contenttypes |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by mag123c):

* cc: mag123c (added)

--
Ticket URL: <https://code.djangoproject.com/ticket/36839#comment:2>

Django

unread,
3:03 PM (1 hour ago) 3:03 PM
to django-...@googlegroups.com
#36839: Renaming of content types on RenameModel operations silently passes when
duplicates are found
-------------------------------------+-------------------------------------
Reporter: Jacob Walls | Owner: Moksha
| Choksi
Type: Bug | Status: assigned
Component: | Version:
contrib.contenttypes |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Moksha Choksi):

* owner: (none) => Moksha Choksi
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/36839#comment:3>
Reply all
Reply to author
Forward
0 new messages