#29893: Unexpected behavior of DetailView on a model defining __len__() returning False -------------------------------+-------------------------------------- Reporter: Max | Owner: Max Type: Bug | Status: assigned Component: Generic views | Version: 2.1 Severity: Normal | Resolution: Keywords: | Triage Stage: Unreviewed Has patch: 1 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------+--------------------------------------
Comment (by Simon Charette): I guess adding an `is None` would do for this case but I wouldn't be surprised if a lot of other cases still break. For example, there's probably a few model forms or admin APIs that do something along `if self.instance` and would need to be adjusted as well. Given defining `__len__()` on a model instance is an edge case and your issue can be worked around by defining a `def __bool__(self): return True` I'm tempted to close this issue as _wont fix_ but I'll let other contributors chime in. I feel like the burden of making sure all APIs dealing with optional model instances truthiness appropriately is not worth the small benefit here. -- Ticket URL: <https://code.djangoproject.com/ticket/29893#comment:2> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/067.f852c143abf9a58092095bc7cb3422c2%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.