Skip to content

Commit

Permalink
Don't include metadata of custom attributes.
Browse files Browse the repository at this point in the history
  • Loading branch information
wRAR committed Aug 20, 2024
1 parent 9289399 commit 35ff1ce
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion scrapy_zyte_api/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ async def __call__( # noqa: C901
result = cls_stripped.from_dict(api_response.raw_api_response[kw]) # type: ignore[attr-defined]
custom_attrs = api_response.raw_api_response.get("customAttributes")

Check warning on line 330 in scrapy_zyte_api/providers.py

View check run for this annotation

Codecov / codecov/patch

scrapy_zyte_api/providers.py#L330

Added line #L330 was not covered by tests
if custom_attrs:
result.customAttributes = custom_attrs # type: ignore[attr-defined]
result.customAttributes = custom_attrs.get("values", {}) # type: ignore[attr-defined]

Check warning on line 332 in scrapy_zyte_api/providers.py

View check run for this annotation

Codecov / codecov/patch

scrapy_zyte_api/providers.py#L332

Added line #L332 was not covered by tests
if is_typing_annotated(cls):
result = AnnotatedInstance(result, cls.__metadata__) # type: ignore[attr-defined]
results.append(result)
Expand Down
9 changes: 7 additions & 2 deletions tests/mockserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,13 @@ def render_POST(self, request):

if "customAttributes" in request_data:
response_data["customAttributes"] = {
"attr1": "foo",
"attr2": 42,
"metadata": {
"totalInputTokens": "1000",
},
"values": {
"attr1": "foo",
"attr2": 42,
},
}

return json.dumps(response_data).encode()
Expand Down

0 comments on commit 35ff1ce

Please sign in to comment.