Fix type handling to support union type #118

Closed
opened 2026-01-07 04:31:14 +00:00 by hurui200320 · 1 comment
Member

According to Luis, cleverswarm now accept optional file upload. When the file is not present, the code shoud provide a None value:

	async def create_extract_with_ontology(unstructured: Annotated[UploadFile,
                                                        File(descripton="Unstructured text file for KG extraction")],
                                       ontology_spec: Annotated[UploadFile,
                                                        File(descripton="Mandatory RDFS/OWL ontology file")],
                                       ontology: Annotated[UploadFile | SkipJsonSchema[None],
                                                           File(descripton="Optional JSON ontology support file"),
                                                           BeforeValidator(empty_str_to_none)] = None,
                                       file_type: FileTypeAPI = Query(default=FileTypeAPI.AutoDetect,
                                                                      title='File type',
                                                                      description='Force a given file type',
                                                                      examples=['AutoDetect',
                                                                                'PlainText',
                                                                                'MarkDown']),
                                       authenticated_user: UserSchema = Depends(get_current_user)):

Notice the type: ontology: Annotated[UploadFile | SkipJsonSchema[None], ...), when the request doesn't contain any file part for parameter ontology, we should provide a None.

Right now the python adapter will give an error:

2026-01-06 18:42:35,910 - root - ERROR - 139928306423488:0.2.63 [E] 'Request handler: 'types.UnionType' object has no attribute '__name__'' ---> '/home/corerasurae/.venv-swarm-eps-micro-3.12-pdf-ner4k/lib/python3.12/site-packages/amqp/adapter/cleverthis_service_adapter.py':673, 'handle_body_payload()'

The related method: https://git.cleverthis.com/clevermicro/amq-adapter-python/src/branch/develop/src/amqp/adapter/cleverthis_service_adapter.py#L558

According to Luis, cleverswarm now accept optional file upload. When the file is not present, the code shoud provide a None value: ```python async def create_extract_with_ontology(unstructured: Annotated[UploadFile, File(descripton="Unstructured text file for KG extraction")], ontology_spec: Annotated[UploadFile, File(descripton="Mandatory RDFS/OWL ontology file")], ontology: Annotated[UploadFile | SkipJsonSchema[None], File(descripton="Optional JSON ontology support file"), BeforeValidator(empty_str_to_none)] = None, file_type: FileTypeAPI = Query(default=FileTypeAPI.AutoDetect, title='File type', description='Force a given file type', examples=['AutoDetect', 'PlainText', 'MarkDown']), authenticated_user: UserSchema = Depends(get_current_user)): ``` Notice the type: `ontology: Annotated[UploadFile | SkipJsonSchema[None], ...)`, when the request doesn't contain any file part for parameter `ontology`, we should provide a `None`. Right now the python adapter will give an error: ``` 2026-01-06 18:42:35,910 - root - ERROR - 139928306423488:0.2.63 [E] 'Request handler: 'types.UnionType' object has no attribute '__name__'' ---> '/home/corerasurae/.venv-swarm-eps-micro-3.12-pdf-ner4k/lib/python3.12/site-packages/amqp/adapter/cleverthis_service_adapter.py':673, 'handle_body_payload()' ``` The related method: https://git.cleverthis.com/clevermicro/amq-adapter-python/src/branch/develop/src/amqp/adapter/cleverthis_service_adapter.py#L558
hurui200320 added this to the V.01 milestone 2026-01-07 08:45:23 +00:00
Author
Member

As discussed with Drew, the work has been paused. CleverSwarm will use a workaround to continue. This ticket will be paused until it becomes a thing in the future

As discussed with Drew, the work has been paused. CleverSwarm will use a workaround to continue. This ticket will be paused until it becomes a thing in the future
hurui200320 changed title from Provide None value for optional file upload parameter to Fix type handling to support union type 2026-01-16 08:42:20 +00:00
hurui200320 2026-01-19 11:40:39 +00:00
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Depends on
#121 Various bug fixes
clevermicro/amq-adapter-python
Reference
clevermicro/amq-adapter-python#118
No description provided.