Skip to content

Commit

Permalink
fix pep8
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelweingartner committed Feb 14, 2025
1 parent 681eec9 commit 5d0bb33
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
def upgrade():
sql_column = sqlalchemy.Column(
"last_measure_timestamp", sqlalchemy.DateTime,
nullable=False, default=datetime.datetime.now(datetime.UTC),
nullable=False, default=datetime.datetime.utcnow(),
server_default=sqlalchemy.sql.func.current_timestamp())
op.add_column(
"metric", sql_column)
2 changes: 1 addition & 1 deletion gnocchi/indexer/sqlalchemy_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class Metric(Base, GnocchiBase, indexer.Metric):
# measurements; thus, if all metric for a resource are in this situation,
# chances are that the resource ceased existing in the backend.
last_measure_timestamp = sqlalchemy.Column(
"last_measure_timestamp", sqlalchemy.DateTime, default=datetime.datetime.now(datetime.UTC), nullable=False,
"last_measure_timestamp", sqlalchemy.DateTime, default=datetime.datetime.utcnow(), nullable=False,
server_default=sqlalchemy.sql.func.current_timestamp())

def jsonify(self):
Expand Down
9 changes: 5 additions & 4 deletions gnocchi/tests/indexer/sqlalchemy/test_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,18 @@ def compare_server_default(self, ctxt, ins_col, meta_col, insp_def, meta_def, re
"""


method_return = super(ModelsMigrationsSync, self).compare_server_default(ctxt, ins_col, meta_col, insp_def,
meta_def, rendered_meta_def)

is_meta_column_default_timestamp = isinstance(meta_def.arg, sa.sql.functions.current_timestamp)
is_reflected_column_default_text_type = isinstance(ins_col.server_default.arg, sa.sql.elements.TextClause)
is_meta_column_default_timestamp = meta_def is not None and isinstance(
meta_def.arg, sa.sql.functions.current_timestamp)
is_reflected_column_default_text_type = ins_col is not None and ins_col.server_default is not None and \
isinstance(ins_col.server_default.arg, sa.sql.elements.TextClause)

is_server_default_current_timestamp = is_meta_column_default_timestamp and is_reflected_column_default_text_type

if not is_server_default_current_timestamp:
return method_return

# If it is different from "CURRENT_TIMESTAMP", then we must throw an error.
# If it is different from "CURRENT_TIMESTAMP", then we must return True, so the test flow continues.
return rendered_meta_def != "CURRENT_TIMESTAMP"

0 comments on commit 5d0bb33

Please sign in to comment.