I am saving an object in SQl Alchemy using:
def save_reply(self, reply: PostgresReplyTable) -> PostgresReplyTable:
"""
Save a reply
Args:
job: The job to save the reply for
text: The text of the reply
Returns:
PostgresReplyTable: The reply
"""
reply = self._session.merge(reply)
self._session.commit()
return reply
The debugger shows the used_prompt_id filed has a value:
/postgres_connector.py(444)save_reply()
-> self._session.commit()
(Pdb) reply
<database_sdk.models.reply.PostgresReplyTable object at 0x7fd3d0179240>
(Pdb) reply.used_prompt_id
2
Yes doing the commit I get the error:
(Pdb) n
sqlalchemy.exc.IntegrityError: (psycopg2.errors.NotNullViolation) null value in column “used_prompt_id” of relation “reply” violates not-null constraint
DETAIL: Failing row contains (1, This is a reply to the job based on the use case requirements., d4e8e3e7-8a8c-4f2e-8e5e-0e2a7a3c9b0d, 2, null, null, null, null, 2024-06-10 11:59:40.913716, 2024-06-10 11:59:40.913724, 2024-06-10 11:59:40.254929).
[SQL: UPDATE reply SET used_prompt_id=%(used_prompt_id)s WHERE reply.reply_id = %(reply_reply_id)s]
[parameters: {‘used_prompt_id’: None, ‘reply_reply_id’: 1}]
(Background on this error at: https://sqlalche.me/e/20/gkpj)
2
Debugging shows the value of the used_prompt_id field is there. I do not understand why the commit is failing