Run Model with Python, python deletes outputs?

600
6
Jump to solution
04-08-2021 06:52 AM
JamesHood
Occasional Contributor

I created a model using ArcMap 10.8  and save in toolbox. 
It starts by creating a new  FGDB with _TodaysDate variable in the name and saving to local drive. 
Then generates a number of feature classes and saves into GDB. 
Then using those intermediate outputs, appends data to SDE feature classes. 
That is it. 

The model does not have any delete functionality (except delete features on some SDE feature classes that are being appended to).

The model runs successfully in model builder edit mode, including the updates to SDE, and the creation of FGDB and all the intermediate Feature classes inside. 

When I run the model from Python 2.7 it runs successfully and updates the SDE  but the feature classes inside the FGDB get deleted before python finishes executing. 

The FGDB does not get deleted. 

The only thing the python does is  is execute the model and then email me to tell me about it.   No deleting is programmed. 

What could be causing the feature classes to get deleted after the append which is the last step in the model?   

Any Thoughts?

Edit to add relevant code from python:

#model update
m1 = "m1 not complete "
m2 = "m2 not complete "
try:

    tbx = arcpy.AddToolbox(r"E:/toolboxpath/toolbox.tbx")
    print tbx
    print "model update started"

    tbx.PRODNS()
    m1 = "m1 Complete"
    tbx.PRODSAO()
    m2 = "m2 Complete"
    print "model update complete"
    
    send_email('not_my_real_email@fakeemail.fake',
           'CENSUS DATA UPDATED',
           'CENSUS DATA UPDATED BOTH MODELS', 
           '')

except arcpy.ExecuteError:
    message = str(m1 + m2 + arcpy.GetMessages(2))
    print(arcpy.GetMessages(2))
    send_email('not_my_real_email@fakeemail.fake',
           'FAILED CENSUS UPDATE FAILED',
           message, 
           '')

 

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JamesHood
Occasional Contributor

It turns out thanks to ESRI support, that the issue is in Model Builder, each output has a parameter that marks it as "Intermediate" or not.  When checked the model deletes the intermediate at conclusion of the model. 
This does not apply if running the model within Model Builder, but does apply if executing the model outside of Model Builder such as with python.   Right click the output of the tool and uncheck "Intermediate" to turn this off. 

https://desktop.arcgis.com/en/arcmap/latest/analyze/modelbuilder/preserving-intermediate-data.htm

 

View solution in original post

6 Replies
JoeBorgione
MVP Esteemed Contributor

Did you  do the model to python conversion?  Sometimes that will goof on you..  Perhaps you could post your code using the Insert/Edit Code Sample button after expanding the tool bar above.

That should just about do it....
0 Kudos
JamesHood
Occasional Contributor

Hi, 

I did not convert model to python, just executing model from python as a means to run as a scheduled task. 
I added the relevant python code but I don't think that's the source of the problem because it doesn't do much. 

Thanks, 

James

0 Kudos
JoeBorgione
MVP Esteemed Contributor

Can't you just run the model as a scheduled task without python calling it?  I don't do models, just python so I don't know why it would clobber your model output.

That should just about do it....
0 Kudos
JamesHood
Occasional Contributor

I don't think models can be scheduled tasks unless run as python.
https://support.esri.com/en/technical-article/000009370

Thanks for your help.  

JoeBorgione
MVP Esteemed Contributor

Just goes to show what I know about using models...

That should just about do it....
0 Kudos
JamesHood
Occasional Contributor

It turns out thanks to ESRI support, that the issue is in Model Builder, each output has a parameter that marks it as "Intermediate" or not.  When checked the model deletes the intermediate at conclusion of the model. 
This does not apply if running the model within Model Builder, but does apply if executing the model outside of Model Builder such as with python.   Right click the output of the tool and uncheck "Intermediate" to turn this off. 

https://desktop.arcgis.com/en/arcmap/latest/analyze/modelbuilder/preserving-intermediate-data.htm