#30309: Remove hasattr reference in One-to-One documentation example
-------------------------------+--------------------------------------
Reporter: David Beitey | Owner: nobody
Type: Uncategorized | Status: closed
Component: Documentation | Version: 2.2
Severity: Normal | Resolution: invalid
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 David Beitey):
In my experience today, using `hasattr(p2, 'restaurant')` is throwing a
`ObjectDoesNotExist` exception with Django 2.1.7 / Python 3.7 and the
exception is not being swallowed. This was the reason for me making the
contribution. For note, I'm not the only one to making this observation:
https://stackoverflow.com/a/22240021/1048705 -- the last paragraph of that
answer.
If it's Django-specific behaviour to add `hasattr` functionality to
swallow errors, then perhaps a bug report is necessary instead of a
documentation fix. If Django is doing this, I'd suggest changing the
behaviour so Django follows Python itself; why Python made the change
explained on the mailing list: https://mail.python.org/pipermail/python-
dev/2010-August/103178.html
Are we able to re-open this? Happy to do further diagnosis if you can't
replicate the exception being raised.
Fwiw, I understand the use case for avoiding exception handling with a
`OneToOneField` - I'd love a clean solution for this myself.
--
Ticket URL: <https://code.djangoproject.com/ticket/30309#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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/065.5ec5faec86741fd7cd876dcd52b7e67b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.