terminusdb / terminusdb/terminusdb-client-python
Python schema doesn't accept optional attributes of types ```List``` and ```Set```
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 80
- Forks
- 62
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
Describe the bug
The Python schema.py does not allow attributes to be the type of List or Set, when they are meant to be optional.
To Reproduce
When I try to commit the following code using tdbpy commit:
class Organization(DocumentTemplate):
name: Optional[str]
id: Optional[str]
identifier: Optional[Identifier]
additionalIdentifiers: Optional[Identifier]
address: Optional[Address]
contactPoint: Optional[ContactPoint]
roles: Optional[List[str]]
I get the following error message:
Error logs
Traceback (most recent call last):
File "/home/micgor32/.local/bin/tdbpy", line 8, in <module>
sys.exit(tdbpy())
^^^^^^^
File "/home/micgor32/.local/pipx/venvs/terminusdb-client/lib/python3.11/site-packages/click/core.py", line 1130, in __call__
return self.main(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/micgor32/.local/pipx/venvs/terminusdb-client/lib/python3.11/site-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
^^^^^^^^^^^^^^^^
File "/home/micgor32/.local/pipx/venvs/terminusdb-client/lib/python3.11/site-packages/click/core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/micgor32/.local/pipx/venvs/terminusdb-client/lib/python3.11/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/micgor32/.local/pipx/venvs/terminusdb-client/lib/python3.11/site-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/micgor32/.local/pipx/venvs/terminusdb-client/lib/python3.11/site-packages/terminusdb_client/scripts/scripts.py", line 361, in commit
schema_obj.commit(client, commit_msg=message, full_replace=True)
File "/home/micgor32/.local/pipx/venvs/terminusdb-client/lib/python3.11/site-packages/terminusdb_client/schema/schema.py", line 676, in commit
client.insert_document(
File "/home/micgor32/.local/pipx/venvs/terminusdb-client/lib/python3.11/site-packages/terminusdb_client/client/Client.py", line 1248, in insert_document
result = json.loads(_finish_response(result))
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/micgor32/.local/pipx/venvs/terminusdb-client/lib/python3.11/site-packages/terminusdb_client/woql_utils.py", line 52, in _finish_response
raise DatabaseError(request_response)
terminusdb_client.errors.DatabaseError: Type error for json{'@class':"xsd:string",'@type':"List"} which should be text
{
"api:message": "Type error for json{'@class':\"xsd:string\",'@type':\"List\"} which should be text",
"api:status": "api:failure",
"system:witnesses": [
{
"@type": "vio:ViolationWithDatatypeObject",
"vio:literal": "json{'@class':\"xsd:string\",'@type':\"List\"}",
"vio:message": "Type error for json{'@class':\"xsd:string\",'@type':\"List\"} which should be text",
"vio:type": "text"
}
]
}
Same happens when roles: Optional[List[str]] is changed to roles: Optional[Set[str]].
Expected behavior
I would expect the changes to be accepted and added to the schema.
System information (please complete the following information):
- OS: Docker
- terminus-client-python 10.2.3
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit dem Python-Pfad schema.py, der von tdbpy commit verwendet wird, und verfolge, wie Optional[List[str]] und Optional[Set[str]] vor dem Einfügen konvertiert werden. Reproduziere den gemeldeten DatabaseError mit dem Organization-Beispiel und überprüfe anschließend, dass beide optionalen Collection-Attribute akzeptiert und zum Schema hinzugefügt werden.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- backend-api-design
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100