Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Please see [MIGRATING.md](./MIGRATING.md) for information on breaking changes.

- Endpoints which return system fields before the record list
- Example python script
- Columns with mixed and incompatible datatypes

### Changed

Expand Down
12 changes: 11 additions & 1 deletion src/ldlite/_jsonx.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def _compile_attrs( # noqa: C901, PLR0912, PLR0913
if depth > max_depth:
return
table = _table_name(parents)
qkey = {}
qkey: dict[str, Attr] = {}
for k, a in quasikey.items():
qkey[k] = Attr(a.name, a.datatype, order=1)
arrays: list[tuple[str, list[JsonValue], str]] = []
Expand All @@ -170,6 +170,11 @@ def _compile_attrs( # noqa: C901, PLR0912, PLR0913
if k is None or v is None:
continue
attr = prefix + k
prev_attr = (
newattrs[table][attr]
if table in newattrs and attr in newattrs[table]
else None
)
if isinstance(v, dict):
if depth == max_depth:
newattrs[table][attr] = Attr(
Expand All @@ -181,6 +186,11 @@ def _compile_attrs( # noqa: C901, PLR0912, PLR0913
objects.append((attr, v, k))
elif isinstance(v, list):
arrays.append((attr, v, k))
elif prev_attr and prev_attr.datatype == "varchar":
# If a column has already been through this check
# and determined to be a varchar it means that
# we can't type it as anything more specific later
qkey[attr] = prev_attr
elif isinstance(v, bool):
a = Attr(decode_camel_case(attr), "boolean", order=3)
qkey[attr] = a
Expand Down
39 changes: 39 additions & 0 deletions tests/test_cases/query_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ def case_null_records(self) -> QueryCase:
],
)

# https://github.com/library-data-platform/ldlite/issues/52
def case_erm_keys(self) -> QueryCase:
return QueryCase(
json_depth=3,
Expand Down Expand Up @@ -638,3 +639,41 @@ def case_erm_keys(self) -> QueryCase:
("prefix__t", "id"),
],
)

# https://github.com/library-data-platform/ldlite/issues/54
def case_mixed_uuid(self) -> QueryCase:
return QueryCase(
json_depth=3,
values={
"prefix": [
{
"purchaseOrders": [
{
"id": "aaaa",
"value": "value",
},
{
"id": "b096504a-3d54-4664-9bf5-1b872466fd66",
"value": 15,
},
],
},
],
},
expected_tables=["prefix", "prefix__t", "prefix__tcatalog"],
expected_values={
"prefix__t": (
["id", "value"],
[
("aaaa", "value"),
("b096504a-3d54-4664-9bf5-1b872466fd66", "15"),
],
),
"prefix__tcatalog": (["table_name"], [("prefix__t",)]),
},
expected_indexes=[
("prefix", "__id"),
("prefix__t", "__id"),
("prefix__t", "id"),
],
)
Loading