thenorm thenorm - 1 year ago 62
Python Question

SqlAlchemy can't find record

I have a table called

with columns
, and
. I'd like to find a specific record that I know to exist in the table.

In my unit tests, I create one entry in the table and then try to find it again.

tmp = session.query(DR).filter(DR.dag_id == self.dag_id).first()

print(self.dag_id == tmp.dag_id)
print(self.execution_date == tmp.execution_date)
print(self.run_id == tmp.run_id)

All three print statements print true, but then when perform the following query, no records are found:

DR.dag_id == self.dag_id,
DR.execution_date == self.execution_date,
DR.run_id == self.run_id

Does anyone know why this is happening?


Answer Source

Have you tried the following query?

    DR.dag_id == self.dag_id,
    DR.run_id == self.run_id

If that works the problem may be python datetime equality is being evaluated differently to your database datetime equality.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download