I'm getting an error trying of use the code of this link: Data Catalog Example. At the step 4, just copy pasting all the code provided, authenticating into my GCP Project and testing it.
Everything is ok until it start creating tag template fields...
tag_template = datacatalog_v1.types.TagTemplate()
tag_template.display_name = 'On-premises Tag Template'
tag_template.fields['source'].display_name = 'Source of the data asset'
tag_template.fields['source'].type.primitive_type = \
datacatalog_v1.FieldType.PrimitiveType.STRING.value
it always crash with the same error.
tag_template <proto.marshal.collections.maps.MapComposite object at 0x10fe23310>
Traceback (most recent call last):
File "/Users/ac/Documents/DataCatalog/python_datacatalog/application/sample.py", line 149, in <module>
tag_template.fields['source'].display_name = 'Source of the data asset'
File "/Users/ac/Documents/DataCatalog/python_datacatalog/venv/lib/python3.8/site-packages/proto/marshal/collections/maps.py", line 56, in __getitem__
raise KeyError(key)
KeyError: 'source'
Someone can help me sharing alternatives to do this?
The sample code on the Data Catalog Example is outdated. Did a few changes on the code starting at step 4 (where you are currently stuck). I encountered another error at the next line for primitive type.
tag_template.fields['source'] = datacatalog_v1.types.TagTemplateField()
If you proceed to step 5, an error will pop up
KeyError: 'source'
. If you did not encounter this then it is all good. But if ever you encounter it here is the code to fix that.tag.fields['source'] = datacatalog_v1.types.TagField() #creates key 'source'
I ran the whole script from step 1 to 5.
Output of the script:
Created tag template:
Created tag: