﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
21711	Check for duplicate model names	Aymeric Augustin	nobody	"(Extracted from #21681.)

`ModelBase.__new__` has an interesting behavior: it checks for a model class with the target name in the app registry and return it instead of creating a new class if found.

{{{
# myapp/models.py

from django.db import models

class MyModel(models.Model):
    pass

first_model_class = MyModel  # save a reference

class MyModel(models.Model):
    pass

second_model_class = MyModel  # save a reference

if second_model_class is first_model_class:
    raise RuntimeError(""WTF"")
}}}

It would be better to raise an error in that case than silently return the first model. See also #21679 which is essentially the same issue for applications.


"	Bug	closed	Core (Other)	dev	Normal	fixed	app-loading		Accepted	0	0	0	0	0	0
