I am having an issue trying to change to a historical version on an SDE feature class using Python and arcpy.ChangeVersion_management.

I am able to manually change the version to a specific date and time using ArcMap. I am also able to fully automate the process using ModelBuilder.

When I export the ModelBuilder model to a python script the script runs without error but the version that is selected is the historical version with todays date and not the date selected as the date parameter.

Using Arcmap and the Python window (Geoprocessing -> Python) I can also run the python code without error and the result is the same. The historical layer is selected with the current date and not the date selected as the date parameter.

Here is the Python syntax I am executing:

arcpy.ChangeVersion_management("Parcels", "HISTORICAL", "", "7/1/2013 4:30:00 PM")

I also get the same results using:

historyDate = datetime.datetime(2011, 7, 1)
arcpy.ChangeVersion_management("Parcels", "HISTORICAL", "", historyDate)

while the following throws a RuntimeError:

historyDate = datetime.date(2011, 7, 1)
arcpy.ChangeVersion_management("Parcel", "HISTORICAL", "", historyDate)

Is this a known bug or am I just going about this the wrong way?

  • My guess is that there is a problem with how you define the date. The tool's parameter expect the value to be a Date object, not a String (resources.arcgis.com/en/help/main/10.2/index.html#//…). There is a helpful Esri forums post on this: forums.arcgis.com/threads/… – Alex Tereshenkov Jun 30 '14 at 10:05
  • The line of code was generated from the ArcGIS Model Builders export to Python Script menu command. I changed the python code to use a Date object and the results are the same. The work around from the provided post is to have the end user start with the historical version and then use the function to change to the current version. This workaround won't work for me due to the fact I am scripting the entire process and the historical date comes from a SQL query. – Brad Welborn Jun 30 '14 at 12:55
  • 1
    I understand. You should probably contact Esri Tech Support then. I was not able to get this thing working with arcpy on 10.2.2 either. You could publish your code, though in the question body since it is unclear in what format you get your date object and how you supply this parameter to the ChangeVersion tool. My gut feeling is that we either cannot figure out a right way to supply the date object to the tool (I've used script tool GUI for that, parameter of Date type) or there is a bug with this tool. – Alex Tereshenkov Jun 30 '14 at 14:42
  • 2
    Alex, thanks for taking the time to look at this. Looks like contacting Esri Tech Support is my next step. I will update the question when I get a response from them. – Brad Welborn Jul 1 '14 at 12:44

After some further research I have confirmed that this is a known bug. Hopefully adding this information here will save someone some time in the future as it was not easy to find using Google or the Esri site.

Bug NIM-087927
Submitted: Jan 8, 2013
Status: Open

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.