Skip to content

Commit bc87fff

Browse files
committed
Revert "Fixes for observed production errors (#741)"
This reverts commit f6d6d6d.
1 parent fcfe722 commit bc87fff

File tree

4 files changed

+8
-68
lines changed

4 files changed

+8
-68
lines changed

app/crud/geostore.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
from asyncpg.exceptions import UniqueViolationError
66
from fastapi.logger import logger
7-
from sqlalchemy import Column, MetaData, Table, func
7+
from sqlalchemy import Column, Table, func
88
from sqlalchemy.sql import Select, label
9-
from sqlalchemy.sql.elements import Label, TextClause, quoted_name
9+
from sqlalchemy.sql.elements import Label, TextClause
1010

1111
from app.application import db
1212
from app.errors import (
@@ -61,8 +61,8 @@ async def get_gfw_geostore_from_any_dataset(geostore_id: UUID) -> Geostore:
6161
async def get_geostore_by_version(
6262
dataset: str, version: str, geostore_id: UUID
6363
) -> Geostore:
64-
src_table = Table(version, MetaData(), schema=dataset, quote=True)
65-
src_table.schema = quoted_name(dataset, quote=True)
64+
src_table: Table = db.table(version)
65+
src_table.schema = dataset
6666

6767
where_clause: TextClause = db.text("gfw_geostore_id=:geostore_id")
6868
bind_vals = {"geostore_id": f"{geostore_id}"}

app/routes/datasets/queries.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -724,10 +724,10 @@ def _get_date_conf_derived_layers(
724724
"""Get derived layers that decode our date_conf layers for alert
725725
systems."""
726726
# TODO should these somehow be in the metadata or creation options instead of hardcoded?
727-
# 16435 is number of days from 1970-01-01 to 2015-01-01, and can be used to convert
727+
# 16435 is number of days from 1970-01-01 and 2015-01-01, and can be used to convet
728728
# our encoding of days since 2015 to a number that can be used generally for datetimes
729729
decode_expression = "(A + 16435).astype('datetime64[D]').astype(str)"
730-
encode_expression = "(A.astype('datetime64[D]') - 16435).astype(uint16)"
730+
encode_expression = "(datetime64(A) - 16435).astype(uint16)"
731731
conf_encoding = RasterTable(
732732
default_meaning="not_detected",
733733
rows=[

tests_v2/fixtures/otf_payload/otf_payload.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"no_data": 0,
1515
"raster_table": None,
1616
"decode_expression": "(A + 16435).astype('datetime64[D]').astype(str)",
17-
"encode_expression": "(A.astype('datetime64[D]') - 16435).astype(uint16)",
17+
"encode_expression": "(datetime64(A) - 16435).astype(uint16)",
1818
"source_layer": "my_first_dataset__date_conf",
1919
"calc": "A % 10000",
2020
},

tests_v2/unit/app/crud/test_geostore.py

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,10 @@
1-
import uuid
21
from unittest.mock import patch
32

43
import pytest
54

6-
from app.crud.geostore import (
7-
get_gadm_geostore,
8-
get_gadm_geostore_id,
9-
get_geostore_by_version,
10-
)
5+
from app.crud.geostore import get_gadm_geostore, get_gadm_geostore_id
116
from app.errors import RecordNotFoundError
127

13-
GEOSTORE_ID = uuid.UUID("12345678-1234-5678-1234-567812345678")
14-
15-
16-
@pytest.mark.asyncio
17-
async def test_get_geostore_by_version_quotes_dotted_version_string():
18-
"""Regression test: version strings containing dots (e.g. 'v1.11') must be
19-
double-quoted in the generated SQL.
20-
"""
21-
dataset = "umd_tree_cover_loss"
22-
version = "v1.11"
23-
24-
with patch("app.crud.geostore.db.first") as mock_db_first:
25-
mock_db_first.return_value = None
26-
try:
27-
await get_geostore_by_version(dataset, version, GEOSTORE_ID)
28-
except RecordNotFoundError:
29-
pass
30-
31-
assert mock_db_first.called, "db.first should have been called"
32-
33-
actual_sql = str(
34-
mock_db_first.call_args.args[0].compile(compile_kwargs={"literal_binds": True})
35-
)
36-
37-
# The schema and table must both be double-quoted so that PostgreSQL
38-
# treats the dot in "v1.11" as part of the identifier, not a separator.
39-
assert (
40-
'"umd_tree_cover_loss"."v1.11"' in actual_sql
41-
), f"Expected schema and table to be double-quoted in SQL, but got:\n{actual_sql}"
42-
43-
44-
@pytest.mark.asyncio
45-
async def test_get_geostore_by_version_quotes_undotted_version_string():
46-
"""Ensure that version strings without dots also render correctly and are
47-
quoted, as a sanity check that the fix doesn't break the common case."""
48-
dataset = "umd_tree_cover_loss"
49-
version = "v1"
50-
51-
with patch("app.crud.geostore.db.first") as mock_db_first:
52-
mock_db_first.return_value = None
53-
try:
54-
await get_geostore_by_version(dataset, version, GEOSTORE_ID)
55-
except RecordNotFoundError:
56-
pass
57-
58-
assert mock_db_first.called
59-
60-
actual_sql = str(
61-
mock_db_first.call_args.args[0].compile(compile_kwargs={"literal_binds": True})
62-
)
63-
64-
assert (
65-
'"umd_tree_cover_loss"."v1"' in actual_sql
66-
), f"Expected schema and table to be double-quoted in SQL, but got:\n{actual_sql}"
67-
688

699
@pytest.mark.asyncio
7010
async def test_get_gadm_geostore_generates_correct_sql_for_country_lookup():

0 commit comments

Comments
 (0)