#19969 closed Cleanup/optimization (duplicate)

More useful error message when defining ForeignKey with invalid first argument

Reported by: ojii 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)

Attachments (0)

Change History (2)

comment:1 Changed 14 months ago by claudep

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 Changed 14 months ago by ojii

  • Resolution set to duplicate
  • Status changed from new to closed

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

Add Comment

Modify Ticket

Change Properties
<Author field>
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.