Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for nested callables - like fields.Nested(lambda: NestedSchema()) #113

Merged
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
5 changes: 4 additions & 1 deletion oarepo_ui/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ def dump_empty(schema_or_field):
return []
if isinstance(schema_or_field, (NestedAttribute, fields.Nested)):
field = schema_or_field
return dump_empty(field.nested)
nested_schema = field.nested
if callable(nested_schema):
nested_schema = nested_schema()
return dump_empty(nested_schema)
if isinstance(schema_or_field, fields.Str):
return ""

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = oarepo-ui
version = 5.0.85
version = 5.0.86
description = UI module for invenio 3.5+
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down
2 changes: 2 additions & 0 deletions tests/test_dump_empty.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class SimpleMetadataSchema(ma.Schema):
simple_arr = ma.fields.List(ma.fields.String())
object_arr = ma.fields.List(ma.fields.Nested(NestedSchema))
nested_obj = ma.fields.Nested(NestedSchema)
nested_via_func = ma.fields.Nested(lambda: NestedSchema())

class Meta:
unknown = ma.INCLUDE
Expand Down Expand Up @@ -57,6 +58,7 @@ def test_empty_dump():
"links": None,
"metadata": {
"nested_obj": {"count": None, "title": "", "valid": None},
"nested_via_func": {"count": None, "title": "", "valid": None},
"object_arr": [],
"simple_arr": [],
"title": "",
Expand Down