Skip to content

Commit

Permalink
DB: remove TZ info from get_{observation,timeseries}_history dates
Browse files Browse the repository at this point in the history
Remove timezone data from `t1` and `t2` dates in `get_observation_history` and `get_timeseries_history`.

This fixes `TypeError: can't compare offset-naive and offset-aware datetimes` present in API when request to `/entity/{entity}/{eid}` was made with `date_from` and `date_to` parameters containing timestamps like 1689745000000.
  • Loading branch information
DavidB137 authored Jul 19, 2023
1 parent bf997b8 commit 826e4c0
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions dp3/database/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,8 @@ def get_observation_history(
Returns:
list of dicts (reduced datapoints)
"""
t1 = datetime.fromtimestamp(0) if t1 is None else t1
t2 = datetime.now() if t2 is None else t2
t1 = datetime.fromtimestamp(0) if t1 is None else t1.replace(tzinfo=None)
t2 = datetime.now() if t2 is None else t2.replace(tzinfo=None)

# Get attribute history
mr = self.get_master_record(etype, eid)
Expand Down Expand Up @@ -565,8 +565,8 @@ def get_timeseries_history(
Returns:
list of dicts (reduced datapoints) - each represents just one point at time
"""
t1 = datetime.fromtimestamp(0) if t1 is None else t1
t2 = datetime.now() if t2 is None else t2
t1 = datetime.fromtimestamp(0) if t1 is None else t1.replace(tzinfo=None)
t2 = datetime.now() if t2 is None else t2.replace(tzinfo=None)

attr_history = self.get_observation_history(etype, attr_name, eid, t1, t2, sort)
if not attr_history:
Expand Down

0 comments on commit 826e4c0

Please sign in to comment.