Skip to content

service: return raw data for non-entity Collection function imports - #335

Open
VitorCoelho wants to merge 1 commit into
SAP:masterfrom
VitorCoelho:fix/function-import-non-entity-collection
Open

VitorCoelho wants to merge 1 commit into
SAP:masterfrom
VitorCoelho:fix/function-import-non-entity-collection

Conversation

@VitorCoelho

Copy link
Copy Markdown
Contributor

Since 1.12.0 (#298), a Function Import whose ReturnType is a Collection(...) is turned into a list of EntityProxy objects, and the handler first looks up fimport.entity_set_name. Collections of primitive or complex types have no EntitySet, so calling such a function import now fails:

KeyError: 'EntitySet None does not exist in any Schema Namespace'

for example with ReturnType="Collection(Edm.String)" or ReturnType="Collection(NS.SomeComplexType)". Up to 1.11.2 these calls returned the raw d payload.

Change

  • service: only build EntityProxy objects when the collection item type is an EntityType; other collections return the raw response data again, exactly as in 1.11.2.
  • tests/metadata.xml: two function imports, Collection(Edm.String) and Collection(EXAMPLE_SRV.ComplexNumber).
  • Tests for both (they fail on master with the KeyError); test_edmx_function_imports lists the two new names.
  • CHANGELOG (Unreleased / Fixed).

Compatibility

Collections of entity types behave as before. For primitive and complex collections, the 1.12.x code path could not return anything (it raised KeyError, or AttributeError ... key_proprties when an EntitySet attribute was declared anyway), so nobody can depend on it; restoring the 1.11.2 output keeps existing callers working. Returning a typed list (e.g. ListWithTotalCount of converted values) could be a follow-up if you prefer that, but it would change what 1.11.x users get, so I left it out.

Tests

  • pytest: 320 passed on Python 3.10, 3.11, 3.12, 3.13 and 3.14.
  • pylint 10.00/10 and flake8 clean on pyodata/ (what make lint checks); flake8 reports nothing on the new test lines.
  • Same script against PyPI 1.11.2 / 1.12.2 / this branch: 1.11.2 and this branch return identical values for both {"d": {"results": [...]}} and {"d": [...]} payloads; 1.12.2 raises KeyError.

Since 1.12.0 every Function Import whose ReturnType is a Collection is
wrapped into EntityProxy objects, which looks up the EntitySet of the
function import first. Collections of primitive or complex types have
no EntitySet, so calling such a function import raised
KeyError: 'EntitySet None does not exist in any Schema Namespace'.

Only build EntityProxy objects when the collection item type is an
entity type, and return the raw response data for other collections,
as pyodata did up to 1.11.2.

Signed-off-by: VitorCoelho <vitorc195@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant