Skip to content

Commit fb642dd

Browse files
authored
TinyDB: fix query data type casting (#1904)
1 parent 86c81c6 commit fb642dd

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

pygeoapi/provider/tinydb_.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,11 @@ def query(self, offset=0, limit=10, resulttype='results',
181181
if properties:
182182
LOGGER.debug('processing properties')
183183
for prop in properties:
184-
QUERY.append(f"(Q.properties['{prop[0]}']=={prop[1]})")
184+
if isinstance(prop[1], str):
185+
value = f"'{prop[1]}'"
186+
else:
187+
value = prop[1]
188+
QUERY.append(f"(Q.properties['{prop[0]}']=={value})")
185189

186190
QUERY = self._add_search_query(QUERY, q)
187191

tests/test_tinydb_provider.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,16 @@ def test_query(config):
111111
assert results['numberMatched'] == 1
112112
assert results['numberReturned'] == 1
113113

114+
results = p.query(properties=[('STATION_NAME', 'HUMBER RIVER AT WESTON')])
115+
assert len(results['features']) == 10
116+
assert results['numberMatched'] == 50
117+
assert results['numberReturned'] == 10
118+
119+
results = p.query(properties=[('IDENTIFIER', '02HC003.1975-10-03')])
120+
assert len(results['features']) == 1
121+
assert results['numberMatched'] == 1
122+
assert results['numberReturned'] == 1
123+
114124
results = p.query(limit=1)
115125
assert len(results['features']) == 1
116126
assert results['features'][0]['id'] == '02HC003.1975-10-03'

0 commit comments

Comments
 (0)