Re: DoesNotExist behavior in db.models query.py

2017-10-23 Thread James Schneider
On Oct 23, 2017 4:06 PM, "'Aaron C. de Bruyn' via Django users" < django-users@googlegroups.com> wrote: The difference between .filter() and .get() is definitely 'by-design'. When you filter through a list of objects, you could end up with zero, one, or many objects returned. When you call .get(

Re: DoesNotExist behavior in db.models query.py

2017-10-23 Thread steve
Thank you Aaron, I started to figure this all out too as I read the docs more carefully and looked at the source code more thoughtfully. One nuance on the try/except block you propose: doesn't work as expected in the request framework because even though the except block can be stated as you pr

Re: DoesNotExist behavior in db.models query.py

2017-10-23 Thread 'Aaron C. de Bruyn' via Django users
The difference between .filter() and .get() is definitely 'by-design'. When you filter through a list of objects, you could end up with zero, one, or many objects returned. When you call .get(), you are basically saying "I want to get exactly *one* record". If the record is not found, it is cons

Re: DoesNotExist behavior in db.models query.py

2017-10-23 Thread steve
Replying to myself here: as is often the case, the problem lies with my own source code. I was calling MODELNAME.objects.get(modelfieldname1='foo',modelfieldname2='bar') which raises the 500 when no such record exists. Turns out that calling MODELNAME.objects.filter(modelfieldname1='foo',modelf

DoesNotExist behavior in db.models query.py

2017-10-23 Thread steve
I have been tripping over the following exception DoesNotExist: INSERT_YOUR_MODEL_NAME_HERE matching query does not exist. The error is source in django 1.11.2 in db.models query.py file, in the get(self, *args, **kwargs) function, line 378 to be exact ... raise self.model.DoesNotExist(...) .