Skip to main content
Solved

AttributeValidator Pass Nulls


braggken
Supporter
Forum|alt.badge.img+6

The AttributeValidator fails nulls when validating for various types.  Most of the time I would like it to pass nulls.
The obvious work-around is using the NullAttributeMapper to map nulls to some acceptable value for the validation but:
a) this is a pain because you have to do it for all attributes you want to check
b) you have to change these values back to null afterwards so as to not send spurious data to the writer

Any more elegant way to do this?
Perhaps a custom transformer to do the work-around and the AttributeValidator within?
Or should this be an “Idea” for the AttributeValidator, i.e. Option: pass nulls?

Best answer by ebygomm

import fme
import fmeobjects
import re

def processFeature(feature):
    validation = feature.getAttribute('_fme_validation_message_list{}')
    for v in validation:
        a = re.search('(?<=\').*?(?=\')',v)
        isNull, Missing, type = feature.getAttributeNullMissingAndType(a.group(0)) 
        if isNull:
            validation.remove(v)
    feature.removeAttribute('_fme_validation_message_list{}')
    feature.removeAttribute('_fme_validation_message')
    feature.setAttribute("numbererrors",len(validation))
    if len(validation)>0:

        feature.setAttribute('_fme_validation_message_list{}',validation)

Dug out the example (my python skills are fairly basic so no doubt this could be better). The main thing for my use case was I had to distinguish between nulls which were valid and empty or missing attributes which were not. In the validation message null, empty and missing are all displayed as ‘’ and can’t be distinguished from each other.

View original
Did this help you find an answer to your question?

6 replies

ebygomm
Influencer
Forum|alt.badge.img+39
  • Influencer
  • July 22, 2025

I’ve run into this problem in the past, I think i ended up doing some processing of the failures in python, so that those that only had null validation failures joined up with the passed features. I do think it should be an option to allow nulls when checking for type


nielsgerrits
VIP
Forum|alt.badge.img+56

I you create an Idea you’ll get my vote.


ebygomm
Influencer
Forum|alt.badge.img+39
  • Influencer
  • Best Answer
  • July 22, 2025
import fme
import fmeobjects
import re

def processFeature(feature):
    validation = feature.getAttribute('_fme_validation_message_list{}')
    for v in validation:
        a = re.search('(?<=\').*?(?=\')',v)
        isNull, Missing, type = feature.getAttributeNullMissingAndType(a.group(0)) 
        if isNull:
            validation.remove(v)
    feature.removeAttribute('_fme_validation_message_list{}')
    feature.removeAttribute('_fme_validation_message')
    feature.setAttribute("numbererrors",len(validation))
    if len(validation)>0:

        feature.setAttribute('_fme_validation_message_list{}',validation)

Dug out the example (my python skills are fairly basic so no doubt this could be better). The main thing for my use case was I had to distinguish between nulls which were valid and empty or missing attributes which were not. In the validation message null, empty and missing are all displayed as ‘’ and can’t be distinguished from each other.


geomancer
Evangelist
Forum|alt.badge.img+51
  • Evangelist
  • July 22, 2025

Simply upvote this idea: 

 


geomancer
Evangelist
Forum|alt.badge.img+51
  • Evangelist
  • July 22, 2025

Interesting… 

A string that is <null> or <missing> is a valid string.

But a number that is <null> or <missing> is not a valid number.

 


braggken
Supporter
Forum|alt.badge.img+6
  • Author
  • Supporter
  • July 23, 2025

Thanks a lot ​@ebygomm  I will definitely borrow that python code! And no your python skill are not “fairly basic”  😅  - I’ve “borrowed” some of your other code from here before and it has been very helpful (something about creating lists if I recall) .

And yes good point ​@geomancer,  indeed composite tests would solve this.  In fact I keep expecting to see composite tests in the AttributeValidator transformer but alas no 😢.  I upvoted the idea.


Reply


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