-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
decouple database connection #74
Conversation
elif isinstance(e.orig, psycopg2.errors.ForeignKeyViolation): | ||
raise errors.ForeignKeyError("collection does not exist") from e | ||
logger.error(e, exc_info=True) | ||
raise errors.DatabaseError("unhandled database error") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need a catch-all exception handler here?
raise errors.DatabaseError("unhandled database error") | |
raise errors.DatabaseError("unhandled database error") | |
except Exception as e: | |
logger.error(e, exc_info=True) | |
raise errors.DatabaseError("unhandled database error") | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes good catch, we need to handle exceptions from get_db
which are not of IntegrityError
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
catch-all exception handler doesn't work here because there are other exceptions that might get thrown within the context of a database session (like NotFoundError
). These exceptions end up getting lost in the catch-all exception handler which then impacts response codes.
Instead I've updated the except
to use a lower-level sqlalchemy exception. It's the lowest level that includes the wrapped psycopg2 error (e.orig
) that we need to determine what error to throw. It should cover any error which occurs during the execution of a SQL statement, which I think covers our requirements here.
Moving the management of database resources to the client, instead of the API. Ref #57 #71
stac_api.clients.postgres.session.Session
object which usesfastapi-utils
to manage database sessions and commits.PostgresClient
which has been removed.PaginationTokenClient
is now a mixin to align with the spec (pagination is now part of core) and to re-use the database session of the parent class.stac_api.api.app
) no longer references any postgres related code.