You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The library is not able to render anything with strings it seems like. This is also true for more complex classes. The library is able to render the text if the Optional typing is removed.
Expected behaviour:
The field should be rendered as any other string field.
This is True for any Optional field!
This is mainly because on an Optional field, the field can also be null, so something like:
{'anyOf': [{'type': '<type>'}, {'type': 'null'}]}
{'anyOf': [{'$ref': '<ref>'}, {'type': 'null'}]}
Therefore, we could filter the optional properties with only null types like:
deffilter_nullable(property: Dict) ->Dict:
# if it is optional and nullable, it may be# - {'anyOf': [{'type': '<type>'}, {'type': 'null'}]# - {'anyOf': [{'$ref': '<ref>'}, {'type': 'null'}]# we want to remove the "null" typeunion_prop=property.get("oneOf", property.get("anyOf"))
ifunion_propisnotNone:
# Remove the null type, while keeping the `$ref` and other typeswhere= [ifori,dinenumerate(union_prop) ifd.get('type') =="null"]
where.reverse()
foriinwhere:
delunion_prop[i]
iflen(union_prop) ==1: # it is fine, we wrap the type to the original objectforkeyinunion_prop[0]:
property[key] =union_prop[0][key]
delproperty["anyOf"] # now we can delete the keyreturnproperty
and in _render_property:
def_render_property(self, streamlit_app: Any, key: str, property: Dict) ->Any:
# filter the case of optional and nullableproperty=schema_utils.filter_nullable(property)
Describe the bug:
When attempting to run the provided test for optional fields:
https://github.com/LukasMasuch/streamlit-pydantic/blob/390a45aba7bf8caccc297c335715cc141db490af/examples/optional_fields.py
The library is not able to render anything with strings it seems like. This is also true for more complex classes. The library is able to render the text if the Optional typing is removed.
Expected behaviour:
The field should be rendered as any other string field.
Steps to reproduce the issue:
optional_fields.py
example provided in the repositoryTechnical details:
The text was updated successfully, but these errors were encountered: