mirror of
https://github.com/sqlalchemy/sqlalchemy.git
synced 2026-05-06 08:56:51 -04:00
MAINT: cleanup the lasts of datetime.utcnow()
<!-- Provide a general summary of your proposed changes in the Title field above -->
### Description
<!-- Describe your changes in detail -->
I'm chasing some loose datetime.datetime.utcnow() deprecation warning in some test suites, and one of these was seemingly coming from sqlalchemy. It wasn't, but nevertheless these minor cleanup changes may still be found useful.
### Checklist
<!-- go over following points. check them with an `x` if they do apply, (they turn into clickable checkboxes once the PR is submitted, so no need to do everything at once)
-->
This pull request is:
- [x] A documentation / typographical / small typing error fix
- Good to go, no issue or tests are needed
**Have a nice day!**
Closes: #11736
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/11736
Pull-request-sha: 9bee8af8d1
Change-Id: Ib1b85fa3d66b665165d908e7c8394482b714c57f
This commit is contained in:
committed by
sqla-tester
parent
7949426428
commit
6fefae897a
@@ -5,6 +5,7 @@ to selected entities.
|
||||
"""
|
||||
|
||||
import datetime
|
||||
from functools import partial
|
||||
|
||||
from sqlalchemy import Column
|
||||
from sqlalchemy import create_engine
|
||||
@@ -23,7 +24,9 @@ class HasTemporal:
|
||||
"""Mixin that identifies a class as having a timestamp column"""
|
||||
|
||||
timestamp = Column(
|
||||
DateTime, default=datetime.datetime.utcnow, nullable=False
|
||||
DateTime,
|
||||
default=partial(datetime.datetime.now, datetime.timezone.utc),
|
||||
nullable=False,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -3135,7 +3135,9 @@ class QueryEvents(event.Events[Query[Any]]):
|
||||
entity = desc['entity']
|
||||
query = query.filter(entity.deleted == False)
|
||||
|
||||
update_context.values['timestamp'] = datetime.utcnow()
|
||||
update_context.values['timestamp'] = (
|
||||
datetime.datetime.now(datetime.UTC)
|
||||
)
|
||||
return query
|
||||
|
||||
The ``.values`` dictionary of the "update context" object can also
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
from functools import partial
|
||||
import random
|
||||
from typing import List
|
||||
|
||||
@@ -1661,7 +1662,9 @@ class TemporalFixtureTest(testing.fixtures.DeclarativeMappedTest):
|
||||
"""Mixin that identifies a class as having a timestamp column"""
|
||||
|
||||
timestamp = Column(
|
||||
DateTime, default=datetime.datetime.utcnow, nullable=False
|
||||
DateTime,
|
||||
default=partial(datetime.datetime.now, datetime.timezone.utc),
|
||||
nullable=False,
|
||||
)
|
||||
|
||||
cls.HasTemporal = HasTemporal
|
||||
|
||||
Reference in New Issue
Block a user