Question

Unexpected getAllAttributeNames-behavior?

  • 31 October 2016
  • 4 replies
  • 3 views

Badge +1

I have created the following simple test workspace:

The PythonCaller runs the following function

def processFeature:

attr = feature.getAllAttributeNames()

for i in attr:

print i

print feature.getAttributeNullMissingAndType(i)

But the attribute I exposed in AttributeExposer doesn't show up in the attr-list, or in the resulting prints. I would expect getAllAttributeNames() to give me all attributes that a transformer would be able to see - but maybe that's expecting the wrong thing? If so, is there such a python question, showing "all the exposed attributes"?


4 replies

Badge

AttributeExposer just expose an attribute so it is visible as a parameter in following transformers while working in FME Workbench.

If you want the attribute to exists on features, you have to use an AttributeCreator.

Userlevel 2
Badge +17

Hi @fhilding, the AttributeExposer exposes the specified attribute names onto Workbench user interface but it won't create instances of new attributes actually. In other words, exposed attributes have not existed yet.

On the other hand, the getAllAttributeNames method returns a list that contains only existing attribute names. I think that the result you have observed is the correct behavior of the method.

If you want to create new attributes, consider using the AttributeCreator or the AttributeManager, instead of the AttributeExposer.

Badge +1

AttributeExposer just expose an attribute so it is visible as a parameter in following transformers while working in FME Workbench.

If you want the attribute to exists on features, you have to use an AttributeCreator.

Ok, that makes sense. But since the pythoncaller is a transformer, it should be possible to somehow iterate through all the exposed attributes? I mean, they exist in the FME Feature Attributes column on the left hand side.

 

 

Badge +1

Hi @fhilding, the AttributeExposer exposes the specified attribute names onto Workbench user interface but it won't create instances of new attributes actually. In other words, exposed attributes have not existed yet.

On the other hand, the getAllAttributeNames method returns a list that contains only existing attribute names. I think that the result you have observed is the correct behavior of the method.

If you want to create new attributes, consider using the AttributeCreator or the AttributeManager, instead of the AttributeExposer.

This is just a subset of a larger problem with removal of attributes that are missing in all features, but I found https://knowledge.safe.com/questions/3349/remove-all-attributes-with-empty-fields.html and will try a version of that instead.

 

 

Still, it seems there should be some kind of way to get all of them, since they are listed in the left-hand side of the editor window. I mean, I can manually access them, so why can't I access them from some kind of transformer-specific list. Obviously not by calling the feature object, but instead something along the lines of pythonCaller.getExposedAttributes().

 

 

Either way, thanks for the help and the solution in the link :)

 

Reply