#683 closed defect (fixed)
[patch] Saving with custom db_column fails
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | Metasystem | Version: | |
Severity: | normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Given
class Poll(meta.Model): poll_id = meta.IntegerField(db_column="poll_pk", primary_key=True) question = meta.CharField(maxlength=200) pub_date = meta.DateTimeField('date published')
this fails:
from django.models.polls import polls from datetime import datetime p = polls.Poll(question="spam?", pub_date=datetime(2005,10,22,19,22)) p.save() Traceback (most recent call last): File "<stdin>", line 1, in ? File "/usr/lib/python2.4/site-packages/django/utils/functional.py", line 3, in _curried return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + morekwargs.items())) File "/usr/lib/python2.4/site-packages/django/core/meta/__init__.py", line 793, in method_save pk_val = getattr(self, opts.pk.column) AttributeError: 'Poll' object has no attribute 'poll_pk'
but:
p.poll_pk = None p.save() p2 = polls.get_object(question__exact="spam?") >>> p2.poll_pk 2
Attachments (2)
Change History (7)
comment:1 by , 19 years ago
by , 19 years ago
Attachment: | meta__init__.patch added |
---|
patch changing .column to .name when it seems to mean that.
comment:2 by , 19 years ago
Summary: | Saving with PK other than "id" fails → [patch] Saving with PK other than "id" fails |
---|
comment:3 by , 19 years ago
Status: | new → assigned |
---|
comment:4 by , 19 years ago
Summary: | [patch] Saving with PK other than "id" fails → [patch] Saving with custom db_column fails |
---|
by , 19 years ago
Attachment: | 683_fix.patch added |
---|
A patch that fixes it by introducing Field.attname
comment:5 by , 19 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.
OK, unless I'm hugely wrong, this is the tip of an iceberg.
Looking in core.meta.init.py, it seems to me that there're lots of places using field.column when it really means field.name.
Of course, meta.init.py is making my head hurt, so I could be wrong.
Another example of this problem:
On latest trunk, given:
result:
(Note the prints coming out of the .add_choice are my attempts to determine what's going on).
In the hopes that it saves some time, I'm attaching a patch to meta.init.py; I basically changed every place that seemed like it meant ".name" when using ".column"; 9 tests fail, but 8 of these are many_to_one_null not having "a.reporter_id", which I think is related to the problem above, which I can't wrap my head around right now.