Opened 17 years ago
Closed 14 years ago
#10648 closed Cleanup/optimization (wontfix)
Django should warn when creating a model with field called "save".
| Reported by: | Owned by: | nobody | |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 1.0 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Design decision needed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
The following model
class MyModel(models.Model):
save = models.BooleanField(...)
causes error messages like
File "django/db/models/query.py", line 373, in get_or_create
obj.save(force_insert=True)
TypeError: 'bool' object is not callable
Django's ORM should give a more intuitive error message (e.g. in manage.py sql/syncdb) and not allow the user to have models with a field called "save".
Change History (7)
comment:1 by , 17 years ago
| milestone: | → 1.1 |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
comment:2 by , 17 years ago
| Triage Stage: | Accepted → Design decision needed |
|---|
comment:3 by , 17 years ago
| milestone: | 1.1 |
|---|
follow-up: 5 comment:4 by , 17 years ago
If we do this, we shouldn't allow fields to replace any methods that already exist. "save" isn't special. Tend to agree with Jacob, though: this is a standard thing throughout Python. You have to be careful not to override parent class attributes and Django shouldn't try to be a "wrapped in cotton wool" version of Python, even by replacing Python warts.
comment:5 by , 17 years ago
If we do this, we shouldn't allow fields to replace any methods that already exist.
You're right on that one. I am not sure if it is even possible to check that. I leave it up to you to decide. It just took me more time than necessary to figure out why I get strange error messages.
comment:6 by , 15 years ago
| Severity: | → Normal |
|---|---|
| Type: | → Cleanup/optimization |
comment:7 by , 14 years ago
| Easy pickings: | unset |
|---|---|
| Resolution: | → wontfix |
| Status: | new → closed |
| UI/UX: | unset |
I'm closing this ticket for the reasons explained by Jacob and Malcolm above.
I don't believe it's worth trying to catch these errors at validation time, and I'm not even sure it's possible. How could we catch "metaclass = ...", since the Model metaclass won't even kick in?
I'm not totally convinced that we should bother warning here -- at a certain point, we can't just put every single possible mistake into the validation warnings. We need to rely on users to do the right thing.