Opened 17 years ago
Closed 14 years ago
#5931 closed Cleanup/optimization (fixed)
__repr__ for db Fields
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | hv@…, mathieu.agopian@… | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
Hi,
for debugging it is usefull, if repr(mydbfield) displays the name
of the field. Small patch inclusive test attached.
Attachments (4)
Change History (16)
by , 17 years ago
Attachment: | db_models_fields_repr.diff added |
---|
comment:1 by , 17 years ago
Component: | Uncategorized → Database wrapper |
---|---|
Triage Stage: | Unreviewed → Design decision needed |
comment:2 by , 16 years ago
Patch needs improvement: | set |
---|---|
Triage Stage: | Design decision needed → Accepted |
comment:3 by , 15 years ago
Patch needs improvement: | unset |
---|
comment:4 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Cleanup/optimization |
comment:5 by , 14 years ago
Easy pickings: | set |
---|---|
Patch needs improvement: | set |
This looks great but it'd be even better if the tests also covered the 0.001% of use cases (i.e. when the field does not have a name) :-)
comment:6 by , 14 years ago
Cc: | added |
---|---|
Patch needs improvement: | unset |
Here is an updated patch that applies on the current trunk.
I believe there's no way a django.db.models.fields.Field
won't have a name anymore though.
by , 14 years ago
Attachment: | 5931-__repr__-for-db-fields added |
---|
updated patch that applies to the current trunk
follow-up: 8 comment:7 by , 14 years ago
Patch needs improvement: | set |
---|
I think that Julien's comment was referring to a test like:
from django.db.model.fields import CharField my_field = CharField() repr(my_field)
that should reveal the None value in place of the name.
comment:8 by , 14 years ago
Replying to claudep:
I think that Julien's comment was referring to a test like:
from django.db.model.fields import CharField my_field = CharField() repr(my_field)that should reveal the None value in place of the name.
That's correct. There's nothing preventing you from using a Field
on its own, hence the "getattr(self, 'name', None))
" in the patch ;)
comment:9 by , 14 years ago
That said, I also think that <django.db.models.fields.CharField None>
would be rather confusing. If the field doesn't have a name, then simply displaying <django.db.models.fields.CharField>
would be preferable in my opinion.
by , 14 years ago
Attachment: | 5931-__repr__-for-db-fields.diff added |
---|
updated patch taking claudep's and julien's comments into account
comment:10 by , 14 years ago
Patch needs improvement: | unset |
---|
I understand now ;) thanks for the feedbacks and comments!
I've attached an updated patch, with the additional test and the specific case for the Field instantiated without a name.
Please let me know if this needs further improvements!
comment:11 by , 14 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
Seems reasonable. However, the test doesn't show that it works as expected. It shows that when you use a field in a completely non-standard fashion (outside of a model), it reports None. That's maybe 0.001% of the normal use-cases. Testing the other 99%+ would be ideal. :-)