Python SDK import naming error
Affected module Python SDK
Describe the bug I found this code snippet responsible for extracting the entity name to import for the insert/update functions, and the SDK is currently not handling some cases correctly.
In my case, when I call client.create_or_update, this code execute that through the errors since: CreateTestCaseResult gets mapped to testCaseresult, whereas it should be testCaseResult. CreateTableProfileRequest gets mapped to tableprofile, whereas it should be tableProfile.
This causes the import to fail.
https://github.com/open-metadata/OpenMetadata/blob/main/ingestion/src/metadata/ingestion/ometa/ometa_api.py
def get_entity_from_create(self, create: Type[C]) -> Type[T]:
"""
Inversely, import the Entity type based on the create Entity class
"""
class_name = create.__name__.replace("Create", "").replace("Request", "")
file_name = (
class_name.lower()
.replace("glossaryterm", "glossaryTerm")
.replace("dashboarddatamodel", "dashboardDataModel")
.replace("apiendpoint", "apiEndpoint")
.replace("apicollection", "apiCollection")
.replace("testsuite", "testSuite")
.replace("testdefinition", "testDefinition")
.replace("testcase", "testCase")
.replace("searchindex", "searchIndex")
.replace("storedprocedure", "storedProcedure")
.replace("ingestionpipeline", "ingestionPipeline")
.replace("dataproduct", "dataProduct")
.replace("datacontract", "dataContract")
.replace("chatconversation", "chatConversation")
.replace("eventsubscription", "eventSubscription")
)
class_path = ".".join(
filter(
None,
[
self.class_root,
self.entity_path
if not file_name.startswith("test")
and not file_name.startswith("eventSubscription")
else None,
self.get_module_path(create),
self.update_file_name(create, file_name),
],
)
)
entity_class = getattr(
__import__(class_path, globals(), locals(), [class_name]), class_name
)
return entity_class
To Reproduce
config = OpenMetadataConfig(open_metadata_host, open_metadata_token)
_ = OpenMetadata.initialize(config)
client = OpenMetadata.get_default_client()
...
request = CreateTestCaseResult.model_validate(test_case_result)
client.create_or_update(request)
Expected behavior The import should be success. I suggest add all these missing cases to above function.
Version:
- OpenMetadata version: 1.11.6
- OpenMetadata Ingestion package version: 1.11.6.1
Additional context Add any other context about the problem here.
I checked this issue and reproduced the import naming problem in the Python SDK.
Root cause: get_entity_from_create() derives module file names using lowercase + partial replacements, which breaks some camel-case cases:
CreateTestCaseResult->testCaseresult(wrong)CreateTableProfileRequest->tableprofile(wrong)
I have prepared a fix by adding explicit mapping for these special cases and added unit coverage in test_ometa_endpoints.py to avoid regressions.
Note: route support for create_or_update(CreateTestCaseResult) looks like a separate behavior/topic, so I am keeping that out of this fix and confirming with maintainers.
Hey @PubChimps Could you assigned me for this issue?
Hi @Yashsainani123 this is already fixed