Opened 16 years ago

Closed 16 years ago

Last modified 16 years ago

#9903 closed (invalid)

Model._meta._name_map is missing unless you load an object from the database

Reported by: pavlo@… Owned by: nobody
Component: Uncategorized Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I need to be able to validate that input parameters are the same length as the max_length field. I figured out how to get back the field object use Model._meta.get_field_by_name(), but I still want to be able to check whether the field exists before I call that method. My code uses Model._meta._name_map, but it doesn't look like it is instantiated until after you load an object from the database. This seems wrong to me, considering that it is suppose to be an attribute on the model class and not dependent on a particular

In my example below, I show you can't get to _meta._name_map until after you load an object:

In [1]: from graffiti.models import *

In [2]: len(Replica._meta._name_map)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)

/home/pavlo/Documents/Graffiti/graffiti/src/tracker/<ipython console> in <module>()

AttributeError: 'Options' object has no attribute '_name_map'

In [3]: replica = Replica()

In [4]: len(Replica._meta._name_map)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)

/home/pavlo/Documents/Graffiti/graffiti/src/tracker/<ipython console> in <module>()

AttributeError: 'Options' object has no attribute '_name_map'

In [5]: replica = Replica.objects.get(id=1)

In [6]: len(Replica._meta._name_map)
Out[6]: 19

Change History (2)

comment:1 by anonymous, 16 years ago

Resolution: invalid
Status: newclosed

_name_map is an internal cache that you shouldn't access directly. Instead, take a look at the Replica._meta.get_field method.

comment:2 by Gary Wilson, 16 years ago

last comment was me.

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