Question

Error Python Exception <TypeError>: Attribute value cannot be None since 2021.1


Badge +8

Since FME 2021.1 I get many python errors around None values: 

Python Exception <TypeError>: Attribute value cannot be None. Use setAttributeNullWithType() to set a null attribute value. 

Is anyone else having the same issues? It occurs with FME Desktop as well as FME Server


6 replies

Userlevel 4

I just tested and was able to reproduce the issue by doing a simple

feature.setAttribute('my_attribute', None)

This has worked in all previous versions of FME and this change has the potential to break a lot of existing code that relies on being able to set a null value using setAttribute().

@safesoftware safesoftware​ What is the reason for this change in behavior? Do we now have to explicitly test for None values first before attribute assignment, e.g.

if my_value is None:
    feature.setAttributeNullWithType('test', FME_ATTR_UNDEFINED)
else:
    feature.setAttribute('test', my_value)

Maybe I'm missing something here, but this does not look like an improvement to me.

Badge +8

I just tested and was able to reproduce the issue by doing a simple

feature.setAttribute('my_attribute', None)

This has worked in all previous versions of FME and this change has the potential to break a lot of existing code that relies on being able to set a null value using setAttribute().

@safesoftware safesoftware​ What is the reason for this change in behavior? Do we now have to explicitly test for None values first before attribute assignment, e.g.

if my_value is None:
    feature.setAttributeNullWithType('test', FME_ATTR_UNDEFINED)
else:
    feature.setAttribute('test', my_value)

Maybe I'm missing something here, but this does not look like an improvement to me.

Great, thanks for testing. Hopefully it can be fixed really soon!

Edit: the bug also includes the PowerPointWriter for example. I cannot reproduce it with a simple example unfortunately, but as soon as I am able to I'll share it.

Badge +8

I just tested and was able to reproduce the issue by doing a simple

feature.setAttribute('my_attribute', None)

This has worked in all previous versions of FME and this change has the potential to break a lot of existing code that relies on being able to set a null value using setAttribute().

@safesoftware safesoftware​ What is the reason for this change in behavior? Do we now have to explicitly test for None values first before attribute assignment, e.g.

if my_value is None:
    feature.setAttributeNullWithType('test', FME_ATTR_UNDEFINED)
else:
    feature.setAttribute('test', my_value)

Maybe I'm missing something here, but this does not look like an improvement to me.

I'm no python expert: @david_r​ , is there a workaround I can use? (which also works for the standard powerpoint writer?)

Userlevel 4

I'm no python expert: @david_r​ , is there a workaround I can use? (which also works for the standard powerpoint writer?)

If it's just for your own Python code, you can use the if-pattern above. If it's the Python code in e.g. the Powerpoint writer that fails, then you've got no other option than going back to whatever version of FME (e.g. 2020.x) from before this surprise introduction of change in behavior, while waiting for Safe to look into it.

Badge +8

I'm no python expert: @david_r​ , is there a workaround I can use? (which also works for the standard powerpoint writer?)

Unfortunately I discovered the issue after updating FME-server, so there is no way back here for me. But thanks for your help so far

Badge +2

@koenterralytics​ Thanks @david_r​ for the reproduction example. We'll try and get this fixed as soon as possible.

Using:

FMEFeature.setAttributeNullWithType(attrName, attrType) 

is the recommended approach to setting Null. attrType = 0

Reply