-
|
Currently, when job do heartbeat,the latest_heartbeat does not update to db,code in job.py like this: # Update last heartbeat time
with create_session() as session:
# Make the session aware of this object
session.merge(self)
self.latest_heartbeat = timezone.utcnow()
session.commit()However, i think we should update latest_heartbeat to db,code should be like this: # Update last heartbeat time
with create_session() as session:
# Make the session aware of this object
self.latest_heartbeat = timezone.utcnow()
session.merge(self)
session.commit()We should update latest_heartbeat before Is there any reason why latest_heartbeat is not updated in the database when the job do heartbeat? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
|
I believe we dosave it and the way it is done is right. You do not have to "merge" an SQL alchemy object after you change it's state. I am not an sqlalchemy expert and looking at the docs does not give me a definite answer, but I believe this is is how it works. Merge reconciles the state of the object with that one in the database. But if you changed the object field and it is not "deteched", commiting the session to which the object is attached will automaticaly issue SQL statements and save all the changes to the object to the database. This is the whole premise of SQLalchemy that it treats ORM objects as "Python" objects and transparently maps them to the Database records - including modifications. The reversal have been implemented 4 years ago, so I doubt it does not work: #6284 But maybe I am wrong on my understanding of how merge works ? What is your understanding how it works @broholens ? @ashb @uranusjr @hussein-awala - I think you are better "SQLAlchemy" experts to explain some of the underlying behaviour? |
Beta Was this translation helpful? Give feedback.
-
|
i think this should be closed by #34026 |
Beta Was this translation helpful? Give feedback.
i think this should be closed by #34026