New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed #30396 -- Added system checks for uniqueness of indexes and constraints names. #11278
Conversation
daf4a0f
to
8c7276b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any thoughts about adjusting the message to make it clear the check is performed on all models and include them in the message like we did for E028
.
e.g.
- `'foo' index name is not unique amongst models: '
'foo' index name is not unique for model <model>
(whenlen(model list) == 1
).
8c7276b
to
872eaba
Compare
thanks @charettes, I applied your comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cansarigol Thanks for this patch. I left some comments.
django/core/checks/model_checks.py
Outdated
index_names.append(model_index.name) | ||
for model_constraint in model._meta.constraints: | ||
constraint_models.append(model) | ||
constraint_names.append(model_constraint.name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use the same mechanism as for the E020
and models' labels instead of __name__
's, i.e.
indexes = defaultdict(list)
constraints = defaultdict(list)
...
for model_index in model._meta.indexes:
indexes[model_index.name].append(model._meta.label)
for model_constraint in model._meta.constraints:
constraints[model_constraint.name].append(model._meta.label)
docs/ref/checks.txt
Outdated
* **models.E029**: ``<index>`` index name is not unique amongst models: | ||
``<model list>``. | ||
* **models.E030**: ``<constraint>`` constraint name is not unique amongst models: | ||
``<model list>``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe:
* **models.E029**: index name ``<index>`` is not unique for model ``<model>``.
``<model list>``.
* **models.E030**: index name ``<index>`` is not unique amongst models:
``<model list>``.
* **models.E031**: constraint name ``<constraint>`` is not unique for model
``<model>``.
* **models.E032**: constraint name ``<constraint>`` is not unique amongst
models: ``<model list>``.
f38c739
to
616b13d
Compare
thanks, @felixxm, I changed the pr as your comments. Isn't |
@cansarigol |
you're right. besides that, there are multiple objects in plural case. |
I rebased from master, split tests, and added tests for collisions across different apps and from abstract models. |
…straints names. Co-Authored-By: Mariusz Felisiak <felisiak.mariusz@gmail.com>
the code is nicer and more inclusive in this way. thank you for your help @felixxm |
Ticket: #30396