Skip to content

Commit

Permalink
sqlalchemy etween is inclusive - it should be exclusive.
Browse files Browse the repository at this point in the history
  • Loading branch information
dbernstein committed Oct 1, 2024
1 parent 75c023d commit aec4fed
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
14 changes: 12 additions & 2 deletions src/palace/manager/scripts/playtime_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,12 @@ def _fetch_report_records(self, start: datetime, until: datetime) -> Query:
sql_max(coalesce(PlaytimeSummary.title, "")).label("title2"),
count(distinct(PlaytimeSummary.loan_identifier)).label("loan_count"),
)
.where(PlaytimeSummary.timestamp.between(start, until))
.where(
and_(
PlaytimeSummary.timestamp >= start,
PlaytimeSummary.timestamp < until,
)
)
.group_by(
PlaytimeSummary.identifier_str,
PlaytimeSummary.collection_name,
Expand All @@ -257,7 +262,12 @@ def _fetch_report_records(self, start: datetime, until: datetime) -> Query:
coalesce(PlaytimeSummary.title, "").label("title"),
sum(PlaytimeSummary.total_seconds_played).label("total_seconds_played"),
)
.where(PlaytimeSummary.timestamp.between(start, until))
.where(
and_(
PlaytimeSummary.timestamp >= start,
PlaytimeSummary.timestamp < until,
)
)
.group_by(
PlaytimeSummary.identifier_str,
PlaytimeSummary.collection_name,
Expand Down
4 changes: 2 additions & 2 deletions tests/manager/scripts/test_playtime_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,9 +584,9 @@ def test_do_run(
playtime(
db.session, identifier, collection, library, dt1m(4), 2, loan_identifier
)
# one month + 32 days ago : in the future and therefore out of range.
# one month + 31 days ago : out of range of reporting period
playtime(
db.session, identifier, collection, library, dt1m(32), 3, loan_identifier
db.session, identifier, collection, library, dt1m(31), 6, loan_identifier
)
playtime(
db.session, identifier, collection, library, dt1m(-31), 60, loan_identifier
Expand Down

0 comments on commit aec4fed

Please sign in to comment.