mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Fix timezone issues for db fields in recorder (#35719)
The database fields are timezoned via DateTime(timezone=True), so the default value should be timezoned too. When using cockroachdb this is fatal and results in the recorder crashing.
This commit is contained in:
parent
8970fd8a56
commit
6c4a6568f5
@ -1,5 +1,4 @@
|
|||||||
"""Models for SQLAlchemy."""
|
"""Models for SQLAlchemy."""
|
||||||
from datetime import datetime
|
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -39,7 +38,7 @@ class Events(Base): # type: ignore
|
|||||||
event_data = Column(Text)
|
event_data = Column(Text)
|
||||||
origin = Column(String(32))
|
origin = Column(String(32))
|
||||||
time_fired = Column(DateTime(timezone=True), index=True)
|
time_fired = Column(DateTime(timezone=True), index=True)
|
||||||
created = Column(DateTime(timezone=True), default=datetime.utcnow)
|
created = Column(DateTime(timezone=True), default=dt_util.utcnow)
|
||||||
context_id = Column(String(36), index=True)
|
context_id = Column(String(36), index=True)
|
||||||
context_user_id = Column(String(36), index=True)
|
context_user_id = Column(String(36), index=True)
|
||||||
# context_parent_id = Column(String(36), index=True)
|
# context_parent_id = Column(String(36), index=True)
|
||||||
@ -84,9 +83,9 @@ class States(Base): # type: ignore
|
|||||||
state = Column(String(255))
|
state = Column(String(255))
|
||||||
attributes = Column(Text)
|
attributes = Column(Text)
|
||||||
event_id = Column(Integer, ForeignKey("events.event_id"), index=True)
|
event_id = Column(Integer, ForeignKey("events.event_id"), index=True)
|
||||||
last_changed = Column(DateTime(timezone=True), default=datetime.utcnow)
|
last_changed = Column(DateTime(timezone=True), default=dt_util.utcnow)
|
||||||
last_updated = Column(DateTime(timezone=True), default=datetime.utcnow, index=True)
|
last_updated = Column(DateTime(timezone=True), default=dt_util.utcnow, index=True)
|
||||||
created = Column(DateTime(timezone=True), default=datetime.utcnow)
|
created = Column(DateTime(timezone=True), default=dt_util.utcnow)
|
||||||
context_id = Column(String(36), index=True)
|
context_id = Column(String(36), index=True)
|
||||||
context_user_id = Column(String(36), index=True)
|
context_user_id = Column(String(36), index=True)
|
||||||
# context_parent_id = Column(String(36), index=True)
|
# context_parent_id = Column(String(36), index=True)
|
||||||
@ -152,10 +151,10 @@ class RecorderRuns(Base): # type: ignore
|
|||||||
|
|
||||||
__tablename__ = "recorder_runs"
|
__tablename__ = "recorder_runs"
|
||||||
run_id = Column(Integer, primary_key=True)
|
run_id = Column(Integer, primary_key=True)
|
||||||
start = Column(DateTime(timezone=True), default=datetime.utcnow)
|
start = Column(DateTime(timezone=True), default=dt_util.utcnow)
|
||||||
end = Column(DateTime(timezone=True))
|
end = Column(DateTime(timezone=True))
|
||||||
closed_incorrect = Column(Boolean, default=False)
|
closed_incorrect = Column(Boolean, default=False)
|
||||||
created = Column(DateTime(timezone=True), default=datetime.utcnow)
|
created = Column(DateTime(timezone=True), default=dt_util.utcnow)
|
||||||
|
|
||||||
__table_args__ = (Index("ix_recorder_runs_start_end", "start", "end"),)
|
__table_args__ = (Index("ix_recorder_runs_start_end", "start", "end"),)
|
||||||
|
|
||||||
@ -191,7 +190,7 @@ class SchemaChanges(Base): # type: ignore
|
|||||||
__tablename__ = "schema_changes"
|
__tablename__ = "schema_changes"
|
||||||
change_id = Column(Integer, primary_key=True)
|
change_id = Column(Integer, primary_key=True)
|
||||||
schema_version = Column(Integer)
|
schema_version = Column(Integer)
|
||||||
changed = Column(DateTime(timezone=True), default=datetime.utcnow)
|
changed = Column(DateTime(timezone=True), default=dt_util.utcnow)
|
||||||
|
|
||||||
|
|
||||||
def _process_timestamp(ts):
|
def _process_timestamp(ts):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user