Skip to main content

Hi.

I've just encountered a mysterious error in a PythonCaller in a workspace :

2018-11-07 20:17:02| 811.7| 3.9|WARN |Python Exception <NameError>: global name 'feature' is not defined

 

2018-11-07 20:17:02| 811.7| 0.0|WARN |Traceback (most recent call last):

 

File "<string>", line 16, in input

 

NameError: global name 'feature' is not defined

 

 

2018-11-07 20:17:02| 811.7| 0.0|ERROR |Error encountered while calling method `input'

 

2018-11-07 20:17:36| 843.3| 31.5|FATAL |Delete_temp_file(PythonFactory): PythonFactory failed to process feature

 

 

The problem is, that my code in the "Delete_temp_file" PythonCaller transformer doesn't have any variable named "feature" in it (I renamed it from the template's "feature" to "ft") :

import fme

 

import fmeobjects

 

import os

 

 

class FeatureProcessor(object):

 

def __init__(self):

 

pass

 

def input(self,ft):

 

try:

 

pass

 

pthnam = ft.getAttribute('tile_temppath')

 

os.remove(pthnam)

 

except:

 

pass

 

self.pyoutput(ft)

 

def close(self):

 

pass

 

 

Is the error resulting variable "feature" something that's hardcoded behind the scene ?

Cheers

feature is not a variable in the template code, it should not be renamed


Also, you can safely delete all the "pass" lines inside the input()-method. The'yre not the source of the error, but the don't do anything either.


feature is not a variable in the template code, it should not be renamed

Actually, the code works for me both in FME 2018.1 and 2017.1 even when the "feature" parameter has been renamed in the input()-method.


Are you sure you've posted the complete code? I'm not able to reproduce the problem on my side.


Actually, the code works for me both in FME 2018.1 and 2017.1 even when the "feature" parameter has been renamed in the input()-method.

ah, so it does


Another thing, perhaps a bit unrelated: If you simply need a temporary file during your translation, I really recommend using the TempPathnameCreator rather than implementing something in Python.

Upsides of the transformer are:

  • Works seamlessly on Windows, Linux, OSX
  • Respects system settings that define temporary file locations (roaming profiles, etc)
  • No code to write and maintain

And best of all: FME will automatically deletes the temporary directories/files created using this transformer, so you don't have to. It even works if FME crashes.


Another thing, perhaps a bit unrelated: If you simply need a temporary file during your translation, I really recommend using the TempPathnameCreator rather than implementing something in Python.

Upsides of the transformer are:

  • Works seamlessly on Windows, Linux, OSX
  • Respects system settings that define temporary file locations (roaming profiles, etc)
  • No code to write and maintain

And best of all: FME will automatically deletes the temporary directories/files created using this transformer, so you don't have to. It even works if FME crashes.

The PythonCaller doesn't create a temp file, it deletes it.


The PythonCaller doesn't create a temp file, it deletes it.

Indeed, but I'm assuming that the file is created somewhere first :-)

But yeah, perhaps it doesn't apply to your case...


Also, you can safely delete all the "pass" lines inside the input()-method. The'yre not the source of the error, but the don't do anything either.

No, most of the "pass" lines are actually needed, as Python needs at least one line of code in any context.

 

I can see that the web UI has deleted all the relevant indention. How come the possibility to add un-reformatted code in this web UI has been removed ?

feature is not a variable in the template code, it should not be renamed

But why does FME then issue the error message then, naming the offending "feature" variable ?


No, most of the "pass" lines are actually needed, as Python needs at least one line of code in any context.

 

I can see that the web UI has deleted all the relevant indention. How come the possibility to add un-reformatted code in this web UI has been removed ?

There was an update to the forum update earlier this week and Safe is still trying to iron out some wrinkles.

Can you post the code as an attached .txt file? That should hopefully work.


But why does FME then issue the error message then, naming the offending "feature" variable ?

Difficult to tell since I cannot reproduce the issue. Is it possible to post a minimal sample workspace that reproduces the problem?


Can you try adding a feature into the close method? So the last few lines would be:

def close(self):
feature = fmeobjects.FMEFeature() 
pass 

From another case I've seen, I have a feeling this might help.


Can you try adding a feature into the close method? So the last few lines would be:

def close(self):
feature = fmeobjects.FMEFeature() 
pass 

From another case I've seen, I have a feeling this might help.

Sorry, that

 

character isn't required. We're having a few quirks with the latest knowledgebase update.


feature is not a variable in the template code, it should not be renamed

As a curiosity, and renamed "ft" back to "feature" in my code, and now it doesn't err !?!

 

 

Besides the error reference (line 16) was "def close" in which I only have a "pass" statement, prompting me to an assumption error in some hidden "code-behind".

Indeed, but I'm assuming that the file is created somewhere first :-)

But yeah, perhaps it doesn't apply to your case...

It's created by the output of a WMS call written by AttributeFileWriter.


There was an update to the forum update earlier this week and Safe is still trying to iron out some wrinkles.

Can you post the code as an attached .txt file? That should hopefully work.

FME_PythonCaller_error.txt


There was an update to the forum update earlier this week and Safe is still trying to iron out some wrinkles.

Can you post the code as an attached .txt file? That should hopefully work.

I renamed it back to its original, in which "feature" is replaced by "ft" in def input()


Apparently the cause of the error is still as mysterious as when I wrote the question. As it's fairly easy to avoid (don't rename "feature" in input()), I'm closing the question.


Reply