Opened 11 years ago

Closed 11 years ago

#19969 closed Cleanup/optimization (duplicate)

More useful error message when defining ForeignKey with invalid first argument

Reported by: Jonas Obrist Owned by: nobody
Component: Database layer (models, ORM) Version: 1.5
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


When you create a ForeignKey with an invalid first argument (for example None), you get an error message:

AssertionError: ForeignKey(None) is invalid. First parameter to ForeignKey must be either a model, a model name, or the string 'self'

What this does not tell you is what model in what app and what field this error occurs.

I therefore propose that this check is moved to contribute_to_class where we have all the information.

(For the record if anyone stumbles up on this, you can use --traceback which will give you this information)

Change History (2)

comment:1 by Claude Paroz, 11 years ago

After #19923 is committed, we're going to always display tracebacks for this sort of errors. Would you consider that as a valid resolution, or do you think that even with the traceback, the final error message should be improved?

comment:2 by Jonas Obrist, 11 years ago

Resolution: duplicate
Status: newclosed

Always showing traceback will fix this. Want aware of that ticket. Closing.

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