Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#11829 closed (invalid)

django-admin model validation mistake

Reported by: bluejeansummer Owned by: nobody
Component: Core (Management commands) Version: 1.0
Severity: Keywords: model db_column
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

In one of my models I have a field that would be logically be called class, but because it is a reserved word, I renamed the field to class_ (notice the trailing underscore). I also set the db_column kwarg to class. I then run ./manage.py sql tracker, and get this error:

    Error: One or more models did not validate:
    tracker.assignment: "class_": Field names cannot end with underscores, because this would lead to ambiguous queryset filters.

However, when I set the model name to klass, the output shows it recognizes the db_column setting. It seems that the validator should check for that setting before emitting an error. Is there a work around I should use for now? I'd rather not spell "class" with a "k".

System Info:

  • Ubuntu 9.04
  • Django 1.0.2

-- Nick

Change History (2)

comment:1 Changed 5 years ago by ubernostrum

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

Field names ending with underscores are invalid regardless of db_column, because the Python-level query API separates field names/joins/lookup types with underscores; as the error message tells you, ending a field name in an underscore would lead to ambiguity in parsing the Python-level field lookups.

comment:2 Changed 5 years ago by bluejeansummer

I feel like an idiot now for not realizing that. I suppose that's what I get for filing a bug report late at night.

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