Search code examples
pythondjangoobjectgetmodels

Model.objects.get returns nothing


I'm having this weird problem when using Model.objects.get(op1=1,op2=2)

it raises the does not exist error although it exists. Did that ever happen with anyone?

I even checked in my logs to make sure that the log happened when the id already existed in the database.

[2015-04-24 20:18:21,106] ERROR: Couldn't find the model entry: Traceback (most recent call last): DoesNotExist: NpBilling matching query does not exist.

and in the database, the last modified date for this row specifically is 20:18:19.

How could that possible ever happen?! The weird thing is that sometimes it works and sometimes it throws this error.

I tried to use get_or_create but I end up with 2 entries in the database. one of them is what was already created.

Thanks in advance for your help. I would appreciate fast responses and suggestions.


Solution

  • I solved it by using transaction.commit() before my second query.