From 3ba5a751470f9361bb12390b6788009ea73cd816220554a71619a324b636db0d Mon Sep 17 00:00:00 2001 From: Ana Guerrero Date: Thu, 1 Feb 2024 17:05:03 +0000 Subject: [PATCH] - Add patch stop-using-utcnow.patch: * Use a callable wrapping datetime.now(utc) rather than utcnow(). OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/python-Flask-SQLAlchemy?expand=0&rev=14 --- python-Flask-SQLAlchemy.changes | 6 ++ python-Flask-SQLAlchemy.spec | 4 +- stop-using-utcnow.patch | 137 ++++++++++++++++++++++++++++++++ 3 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 stop-using-utcnow.patch diff --git a/python-Flask-SQLAlchemy.changes b/python-Flask-SQLAlchemy.changes index be5a205..29be159 100644 --- a/python-Flask-SQLAlchemy.changes +++ b/python-Flask-SQLAlchemy.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Thu Feb 1 05:13:58 UTC 2024 - Steve Kowalik + +- Add patch stop-using-utcnow.patch: + * Use a callable wrapping datetime.now(utc) rather than utcnow(). + ------------------------------------------------------------------- Thu Oct 19 21:37:17 UTC 2023 - Matej Cepl diff --git a/python-Flask-SQLAlchemy.spec b/python-Flask-SQLAlchemy.spec index 119cc82..814bc76 100644 --- a/python-Flask-SQLAlchemy.spec +++ b/python-Flask-SQLAlchemy.spec @@ -1,7 +1,7 @@ # # spec file for package python-Flask-SQLAlchemy # -# Copyright (c) 2023 SUSE LLC +# Copyright (c) 2024 SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -24,6 +24,8 @@ Summary: SQLAlchemy support for Flask License: BSD-3-Clause URL: https://github.com/mitsuhiko/flask-sqlalchemy Source: https://files.pythonhosted.org/packages/source/f/flask_sqlalchemy/flask_sqlalchemy-%{version}.tar.gz +# PATCH-FIX-UPSTREAM gh#pallets-eco/flask-sqlalchemy#1308 +Patch0: stop-using-utcnow.patch BuildRequires: %{python_module flit-core} BuildRequires: %{python_module pip} BuildRequires: %{python_module wheel} diff --git a/stop-using-utcnow.patch b/stop-using-utcnow.patch new file mode 100644 index 0000000..eed8bf1 --- /dev/null +++ b/stop-using-utcnow.patch @@ -0,0 +1,137 @@ +From 172e2391ab3de16ec7a001226985aec3ee2f8353 Mon Sep 17 00:00:00 2001 +From: Steve Kowalik +Date: Wed, 31 Jan 2024 16:39:57 +1100 +Subject: [PATCH] Stop using datetime.utcnow() in tests + +datetime.utcnow() is deprecated for Python 3.12+, and raises a warning. +Since warnings are treated as errors, this results in test failures. +Since utcnow calls are done by the SQLAlchemy mapping machinery, we need +to use a callable. + +Fixes #1303 +--- + CHANGES.rst | 5 +++++ + tests/test_model.py | 38 ++++++++++++++++++++------------------ + 2 files changed, 25 insertions(+), 18 deletions(-) + +diff --git a/CHANGES.rst b/CHANGES.rst +index 60c7f2b2..afb639d9 100644 +--- a/CHANGES.rst ++++ b/CHANGES.rst +@@ -1,3 +1,8 @@ ++Unreleased ++---------- ++ ++- No longer call ``datetime.utcnow()`` in the test suite. :issue:`1303` ++ + Version 3.1.1 + ------------- + +diff --git a/tests/test_model.py b/tests/test_model.py +index 0968a1e2..dda0a5fa 100644 +--- a/tests/test_model.py ++++ b/tests/test_model.py +@@ -2,6 +2,7 @@ + + import typing as t + from datetime import datetime ++from datetime import timezone + + import pytest + import sqlalchemy as sa +@@ -14,6 +15,11 @@ + from flask_sqlalchemy.model import Model + + ++class UTCNow(datetime): ++ def __new__(cls): # type: ignore[no-untyped-def] ++ return datetime.now(tz=timezone.utc) ++ ++ + def test_default_model_class_1x(app: Flask) -> None: + db = SQLAlchemy(app) + +@@ -147,12 +153,12 @@ def test_abstractmodel(app: Flask, model_class: t.Any) -> None: + class TimestampModel(db.Model): + __abstract__ = True + created: sa_orm.Mapped[datetime] = sa_orm.mapped_column( +- db.DateTime, nullable=False, insert_default=datetime.utcnow, init=False ++ db.DateTime, nullable=False, insert_default=UTCNow, init=False + ) + updated: sa_orm.Mapped[datetime] = sa_orm.mapped_column( + db.DateTime, +- insert_default=datetime.utcnow, +- onupdate=datetime.utcnow, ++ insert_default=UTCNow, ++ onupdate=UTCNow, + init=False, + ) + +@@ -167,10 +173,10 @@ class Post(TimestampModel): + class TimestampModel(db.Model): # type: ignore[no-redef] + __abstract__ = True + created: sa_orm.Mapped[datetime] = sa_orm.mapped_column( +- db.DateTime, nullable=False, default=datetime.utcnow ++ db.DateTime, nullable=False, default=UTCNow + ) + updated: sa_orm.Mapped[datetime] = sa_orm.mapped_column( +- db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow ++ db.DateTime, default=UTCNow, onupdate=UTCNow + ) + + class Post(TimestampModel): # type: ignore[no-redef] +@@ -181,10 +187,8 @@ class Post(TimestampModel): # type: ignore[no-redef] + + class TimestampModel(db.Model): # type: ignore[no-redef] + __abstract__ = True +- created = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) +- updated = db.Column( +- db.DateTime, onupdate=datetime.utcnow, default=datetime.utcnow +- ) ++ created = db.Column(db.DateTime, nullable=False, default=UTCNow) ++ updated = db.Column(db.DateTime, onupdate=UTCNow, default=UTCNow) + + class Post(TimestampModel): # type: ignore[no-redef] + id = db.Column(db.Integer, primary_key=True) +@@ -207,12 +211,12 @@ def test_mixinmodel(app: Flask, model_class: t.Any) -> None: + + class TimestampMixin(sa_orm.MappedAsDataclass): + created: sa_orm.Mapped[datetime] = sa_orm.mapped_column( +- db.DateTime, nullable=False, insert_default=datetime.utcnow, init=False ++ db.DateTime, nullable=False, insert_default=UTCNow, init=False + ) + updated: sa_orm.Mapped[datetime] = sa_orm.mapped_column( + db.DateTime, +- insert_default=datetime.utcnow, +- onupdate=datetime.utcnow, ++ insert_default=UTCNow, ++ onupdate=UTCNow, + init=False, + ) + +@@ -226,10 +230,10 @@ class Post(TimestampMixin, db.Model): + + class TimestampMixin: # type: ignore[no-redef] + created: sa_orm.Mapped[datetime] = sa_orm.mapped_column( +- db.DateTime, nullable=False, default=datetime.utcnow ++ db.DateTime, nullable=False, default=UTCNow + ) + updated: sa_orm.Mapped[datetime] = sa_orm.mapped_column( +- db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow ++ db.DateTime, default=UTCNow, onupdate=UTCNow + ) + + class Post(TimestampMixin, db.Model): # type: ignore[no-redef] +@@ -239,10 +243,8 @@ class Post(TimestampMixin, db.Model): # type: ignore[no-redef] + else: + + class TimestampMixin: # type: ignore[no-redef] +- created = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) +- updated = db.Column( +- db.DateTime, onupdate=datetime.utcnow, default=datetime.utcnow +- ) ++ created = db.Column(db.DateTime, nullable=False, default=UTCNow) ++ updated = db.Column(db.DateTime, onupdate=UTCNow, default=UTCNow) + + class Post(TimestampMixin, db.Model): # type: ignore[no-redef] + id = db.Column(db.Integer, primary_key=True)