Hello,
I could source the issue in a line in EthernetInterface clean() function.
Here is the error triggering line:
other_if = EthernetInterface.objects.exclude(server_host__pk=
self.server_host.pk).filter(MAC=self.MAC).first()
When I replace this line with ones bellow, behaviour is as expected (red 'This field is
required' error message display without any exception throwing):
try:
other_if = EthernetInterface.objects.exclude(server_host__pk=
self.server_host.pk).filter(MAC=self.MAC).first()
except:
other_if = EthernetInterface.objects.filter(MAC=self.MAC).first()
Though it now works as expected, I'm not satisfied with my workaround because I'm catching all errors or exceptions.
1. Within a clean() function body, what is the canonical way to check if a (required) foreign key is currently set or not ?
I tried with "if self.server_host" without success.
I was thinking of accessing some model dict if such exist.
2. How can I import RelatedObjectDoesNotExist errors in my code ?
3. Would you say that throwing an error when executing a simple "if self.server_host" test is a bug (that should be reported) or not ?
Best regards