Skip to content

Fix issues with the jsonstorage table#935

Open
BryceStevenWilley wants to merge 2 commits into
jhpyle:masterfrom
SuffolkLITLab:fix_jsonstorage
Open

Fix issues with the jsonstorage table#935
BryceStevenWilley wants to merge 2 commits into
jhpyle:masterfrom
SuffolkLITLab:fix_jsonstorage

Conversation

@BryceStevenWilley
Copy link
Copy Markdown
Contributor

Tried fixing 3 specific things here:

  1. Changed db.Index to Index. The former doesn't work anymore, giving an error AttributeError: 'Engine' object has no attribute 'Index'.1

  2. We switched our jsonstorage table to an externally hosted SQL database recently and have run into issues in production with

    (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "jsonstorage_pkey" DETAIL: Key (id)=(...) already exists."

    This error has happened twice within a week. This shouldn't be happening, but from reading the SQLAlchemy docs it seems that we need to use server_default to prevent SQL Alchemy from automatically assuming the default of the value? I'm less sure this fix is correct, but it doesn't change current functionality.

  3. When we do run into a call that violates the duplicate key, all other writes to the jsonstorage table will fail with

    This Session's transaction has been rolled back due to a previous exception during flush. To begin a new transaction with this Session, first issue Session.rollback(). Original exception was: (raised as a result of Query-invoked autoflush; consider using a session.no_autoflush block if this flush is occurring prematurely) (psycopg2.errors.UniqueViolation) ...

    To prevent this from happening, this change catches excepts that occur when writing or deleting from the jsonstorage table and calls rollback().

Footnotes

  1. I can't find where this is failing during normal docassemble runs, but the error can be recreated in python.

sqlalchemy doesn't have an `Index` attribute on the `db` Engine object anymore.
Have previously run into errors (duplicate id) that then cascasde and prevent
any user from writing to the jsonstorage table. This change makes the functions
call `rollback()` to properly start a new sqlalchemy transaction and isolate
the DB error to only the original affected user.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant