Skip to main content
Question

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


koenterralytics
Contributor
Forum|alt.badge.img+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

david_r
Celebrity
  • July 16, 2021

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.


koenterralytics
Contributor
Forum|alt.badge.img+8
david_r wrote:

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.


koenterralytics
Contributor
Forum|alt.badge.img+8
david_r wrote:

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?)


david_r
Celebrity
  • July 16, 2021
koenterralytics wrote:

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.


koenterralytics
Contributor
Forum|alt.badge.img+8
koenterralytics wrote:

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


Forum|alt.badge.img+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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings