Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#17388 closed Cleanup/optimization (fixed)

Custom model field methods need to handle None, doc should say so

Reported by: anonymous Owned by: nobody
Component: Documentation Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

Wrote a set of custom model fields to handle ASN.1 DER objects encoded as SQL BLOBs (don't ask). One of those custom model fields is used in a model which allows the field defined with that custom model field to be null. Boom, backtrace, bits everywhere.

In retrospect it's obvious that if the field is allowed to be null, the .to_python() and .get_prep_value() methods have to support None, but it wasn't obvious up front from the documentation.

Not a big deal, the code worked once I figured this out. I'm reporting this in the hope that it might save somebody else a bit of frustration someday.

Many thanks for a great package.

Change History (3)

comment:1 Changed 3 years ago by gabrielhurley

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Sounds like a worthwhile thing to mention in the docs. Thanks for suggesting it. And like you said, I won't ask. ;-)

comment:2 Changed 3 years ago by Tim Graham <timograham@…>

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

In 4cef9a09f9b0d89abf323a1cf8b9e8354e316c18:

Fixed #17388 - Noted in the custom model field docs that field methods need to handle None if the field may be null.

comment:3 Changed 3 years ago by Tim Graham <timograham@…>

In 700717db1f7e3032cfd89ea80f37eb69bc54a188:

[1.4.X] Fixed #17388 - Noted in the custom model field docs that field methods need to handle None if the field may be null.

Backport of 4cef9a09f9 from master

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