Hi - I’m trying to use the python emitter for a cu...
# advice-metadata-modeling
m
Hi - I’m trying to use the python emitter for a custom Aspect. Following https://datahubproject.io/docs/metadata-models-custom, I add a custom aspect to the dataset class that contains a single field:
Copy code
namespace com.oxygen

@Aspect = {
  "name": "customUniverse",
  "autoRender": true,
  "renderSpec": {
    "displayType": "properties", // or tabular
    "key": "universe",
    "displayName": "Universe"
  }
}

record Universe {
    @Searchable = {
        "fieldType": "KEYWORD",
        "enableAutocomplete": true
        "addToFilters": true,
        "filterNameOverride": "Universe"
    }
    universe: string
}
This successfully builds and was added to Datahub
Copy code
"models": {
    "custom-oxygen-model": {
      "0.0.3": {
        "loadResult": "SUCCESS",
        "registryLocation": "/etc/datahub/plugins/models/custom-oxygen-model/0.0.3",
        "failureCount": 0
      }
    },
I now want to use the python emitter to add a value to this aspect
Copy code
mcp=MetadataChangeProposalWrapper(
            entityType="dataset",
            entityUrn=dataset_urn,
            aspectName="customUniverse",
            aspect={"universe": "HELLO WORLD"},  
            changeType=ChangeTypeClass.UPSERT,
            )
        )
If I were using an existing aspect, I would import a class from datahub.metadata.schema_classes to wrap around the aspect data. Just trying to send it in a dictionary allows me to create the workunit, but fails when I try to emit:
AttributeError: 'dict' object has no attribute 'to_obj'
How should I be using the python emitter with their custom aspects?
m
Hey @most-pillow-90882 we don't yet support codegen-ing the python data-classes from the custom model definitions yet. If you have a
dict
that you are trying to send over to DataHub over REST, you can use the
MetadataChangeProposalClass
directly. Here is a gist that shows you how to do it: https://gist.github.com/shirshanka/7bb6889947f4004eaaba0e35675a56df
m
Thank you! Exactly the solution I needed. Wasn’t aware of the
GenericAspectClass