Opened 2 years ago

Closed 2 years ago

#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

Description

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 Changed 2 years 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 2 years 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.

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