-
Notifications
You must be signed in to change notification settings - Fork 803
Closed
Description
Documents declaration works when Optional is used:
class MyDocument(Document):
label: Optional[str]
doc = MyDocument(label="test")
print(doc.full_clean()) # Prints no error ie. Nonehowever more recent syntax for Optional is different:
class MyDocument(Document):
label: str | None
doc = MyDocument(label="test")
print(doc.full_clean()) # prints errorsErrors:
Traceback (most recent call last):
File "/Users/Silver/Projects/GitHub/mybaze/temp.py", line 77, in <module>
main()
File "/Users/Silver/Projects/GitHub/mybaze/temp.py", line 63, in main
class MyDocument(Document):
File "/Users/Silver/Projects/GitHub/mybaze/.venv/lib/python3.12/site-packages/elasticsearch_dsl/_sync/document.py", line 56, in __new__
new_cls = super().__new__(cls, name, bases, attrs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/Silver/Projects/GitHub/mybaze/.venv/lib/python3.12/site-packages/elasticsearch_dsl/document_base.py", line 109, in __new__
attrs["_doc_type"] = DocumentOptions(name, bases, attrs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/Silver/Projects/GitHub/mybaze/.venv/lib/python3.12/site-packages/elasticsearch_dsl/document_base.py", line 236, in __init__
raise TypeError(f"Cannot map field {name}")
TypeError: Cannot map field label
Metadata
Metadata
Assignees
Labels
No labels