-
Notifications
You must be signed in to change notification settings - Fork 48
fix(utc): move DB config override to _apply_driver_defaults #198
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
Changes from 1 commit
f296420
d1a3332
9259692
326e042
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,7 @@ | |
|
|
||
| from flask_sqlalchemy import SQLAlchemy as FlaskSQLAlchemy | ||
| from sqlalchemy import Column, MetaData, event, util | ||
| from sqlalchemy.engine import Engine | ||
| from sqlalchemy.engine import Engine, make_url | ||
| from sqlalchemy.sql import text | ||
| from sqlalchemy.types import DateTime, TypeDecorator | ||
| from werkzeug.local import LocalProxy | ||
|
|
@@ -129,10 +129,12 @@ def __getattr__(self, name): | |
|
|
||
| return super().__getattr__(name) | ||
|
|
||
| def apply_driver_hacks(self, app, sa_url, options): | ||
| def _apply_driver_defaults(self, options, app): | ||
| """Call before engine creation.""" | ||
| # Don't forget to apply hacks defined on parent object. | ||
| super(SQLAlchemy, self).apply_driver_hacks(app, sa_url, options) | ||
| super(SQLAlchemy, self)._apply_driver_defaults(options, app) | ||
|
|
||
| sa_url = make_url(options["url"]) | ||
|
|
||
| if sa_url.drivername == "sqlite": | ||
| connect_args = options.setdefault("connect_args", {}) | ||
|
|
@@ -158,6 +160,13 @@ def adapt_proxy(proxy): | |
| elif sa_url.drivername == "postgresql+psycopg2": # pragma: no cover | ||
| from psycopg2.extensions import adapt, register_adapter | ||
|
|
||
| connect_args = options.setdefault("connect_args", {}) | ||
| if "options" not in connect_args: | ||
|
||
| # Ensure the database is using the UTC timezone for interpreting timestamps (PostgreSQL only). | ||
| # This overrides any default setting (e.g. in postgresql.conf). Invenio expects the DB to receive | ||
| # and provide UTC timestamps in all cases, so it's important that this doesn't get changed. | ||
| connect_args["options"] = "-c timezone=UTC" | ||
|
|
||
| def adapt_proxy(proxy): | ||
| """Get current object and try to adapt it again.""" | ||
| return adapt(proxy._get_current_object()) | ||
|
|
@@ -178,8 +187,6 @@ def escape_local_proxy(val, mapping): | |
| converters.conversions[LocalProxy] = escape_local_proxy | ||
| converters.encoders[LocalProxy] = escape_local_proxy | ||
|
|
||
| return sa_url, options | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yikes, I thought for a minute, we're not actually applying anything, but it looks like
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as i understand Pal, we are not applying anything, since the name has been changed and the method is not called!
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed we don't need to return anything anymore, it uses |
||
|
|
||
|
|
||
| def do_sqlite_connect(dbapi_connection, connection_record): | ||
| """Ensure SQLite checks foreign key constraints. | ||
|
|
||
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.
minor: you could update the comment since the method name has changed.
hacks->defaults