To answer the original question, when calling for filtering, when creating a new set of queries, FieldError and ValueError arise:
>>> a = Account.objects.all() >>> a = a.filter(id=3) >>> a = a.filter(no_exist=3) <snip> FieldError: Cannot resolve keyword 'no_exist' into field. Choices are: active, created_on, group, id, ... >>> a = Account.objects.all() >>> a = a.filter(id='abc') ValueError: invalid literal for int() with base 10: 'abc'
I will also add that this pattern seems confusing to me, as filter usually used to return the / iterable list for models, and not as for get . For clarity and simplification of exception handling, I would suggest this pattern:
kwargs = {} if something: kwargs['foo'] = some_foo if another_thing: kwargs['bar'] = some_bar
Another added benefit is that IIRC, handling cloning requests is relatively expensive, so you ignore this overhead and at the same time make the code cleaner. Returning to your question, there is no question with this scheme where the exception will occur.
source share