Opened 8 years ago

Closed 8 years ago

#27599 closed Bug (fixed)

str(models.Field()) crashes

Reported by: Sergey Fedoseev Owned by: Morgan Aubert
Component: Database layer (models, ORM) Version: 1.8
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

In [1]: from django.db.models import Field

In [2]: str(Field())
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-4740ae05790d> in <module>()
----> 1 str(Field())

/home/sergey/dev/django/django/utils/six.pyc in <lambda>(self)
    840                              klass.__name__)
    841         klass.__unicode__ = klass.__str__
--> 842         klass.__str__ = lambda self: self.__unicode__().encode('utf-8')
    843     return klass
    844

/home/sergey/dev/django/django/db/models/fields/__init__.pyc in __str__(self)
    188     def __str__(self):
    189         """ Return "app_label.model_label.field_name". """
--> 190         model = self.model
    191         app = model._meta.app_label
    192         return '%s.%s.%s' % (app, model._meta.object_name, self.name)

AttributeError: 'Field' object has no attribute 'model'

Change History (5)

comment:1 by Tim Graham, 8 years ago

Triage Stage: UnreviewedAccepted

We could return super() for fields not attached to models -- do you have any other idea in mind?

comment:2 by Tim Graham, 8 years ago

Summary: str(Field()) crashesstr(models.Field()) crashes

in reply to:  1 comment:3 by Morgan Aubert, 8 years ago

Owner: changed from nobody to Morgan Aubert
Status: newassigned

We could return super() for fields not attached to models

It seems like the right thing to do.

comment:4 by Morgan Aubert, 8 years ago

Has patch: set

Added PR

comment:5 by Tim Graham <timograham@…>, 8 years ago

Resolution: fixed
Status: assignedclosed

In ef889d5b:

Fixed #27599 -- Fixed Field.str() crash for fields not attached to models.

Note: See TracTickets for help on using tickets.
Back to Top