import arcpy, datetime indata = arcpy.GetParameter(0) #A feature layer input from the sde.DEFAULT indate = arcpy.GetParameter(1) #A date type input parameter (type = datetime) arcpy.AddMessage(type(indate))#returns datetime.datetime arcpy.AddMessage("Current Data Count: "+str(arcpy.GetCount_management(indata))) #Correctly returns 75 arcpy.ChangeVersion_management(indata, "HISTORICAL", "", indate) arcpy.AddMessage("Old Data Count: "+str(arcpy.GetCount_management(indata)))#Returns 75, but should be returning 100
import arcpy indata = arcpy.GetParameter(0)#Some versioned data in ArcMap (say referencing my point dataset with 100 points). arcpy.AddMessage("getCount gp tool count: "+str(arcpy.GetCount_management(indata))) #This returns a value of 75 (the number of points in sde.DEFAULT) i = 0 with arcpy.da.SearchCursor(indata, ["OBJECTID"]) as cursor: for row in cursor: i+=1 arcpy.AddMessage("search cursor count: "+str(i)) #This returns a value of 100 (the number of points in the versioned dataset)
import arcpy indata = arcpy.GetParameter(0)#A historical SDE version from two days ago arcpy.AddMessage("Versioned data count: "+str(arcpy.GetCount_management(indata))) #Correctly returns 100 points arcpy.ChangeVersion_management(indata, "TRANSACTIONAL", "sde.DEFAULT", '#') arcpy.AddMessage("Default version data count: "+str(arcpy.GetCount_management(indata))) #Correctly returns 75 points
import arcpy arcpy.env.workspace = "blablabla"#my sde connection file location indata = arcpy.GetParameter(0)#My sde.DEFAULT data layer indate = arcpy.GetParameterAsText(1)#Using the date data type input (format: MM/DD/YYYY HH:MM:SS AM) sde_olddata = indata.datasetName+"_H" #access the archive layer. does it always end with "_H"? Mine appear to... if arcpy.Exists(sde_olddata):#Make sure it exists arcpy.AddMessage("the archive version exists!") else: arcpy.AddMessage("your data isn't archive enabled!") #Convert the date to the correct format for SQL queries: (YYYY-MM-DD) if " " in indate: year = int(indate[indate.rfind("/")+1:indate.find(" ")]) else: year = int(indate[indate.rfind("/")+1:]) day = int(indate[indate.find("/")+1:indate.rfind("/")]) month = int(indate[:indate.find("/")]) tstamp = str(year)+"-"+str(month)+"-"+str(day) #Query the archived layer based on the input date olddata = "in_memory\\oldData" arcpy.Select_analysis(sde_olddata, olddata, "gdb_to_date >= timestamp '"+tstamp+"' AND gdb_from_date <= timestamp '"+tstamp+"'") #Count up the number of rows arcpy.AddMessage("Versioned data count: "+str(arcpy.GetCount_management(olddata))) #Correctly returns 100 points arcpy.AddMessage("Default version data count: "+str(arcpy.GetCount_management(indata))) #Correctly returns 75 points
Hi Andrew,
Thanks for your sharings with this issue. Do you encounter the same buggy behaviour with ArcGIS 10.3 and above?
Also, do you have an idea how to create a Historical Marker with arcpy?
Thank you and have a good day!
I have just found the same behaviour in 10.2 I don't have 10.3 or higher to test with. One thing I did notice - If I select the tool in the ArcToolbox -> Data Management Tools -> Versions -> Change Version, and I enter all the information for the historical version, it changes correctly. Then I go into the Geoprocessing results, and I right click on the successful action, and Copy as Python Snippet, and I paste that into the python window, and run it again, I immediately get the incorrect behaviour of it changing to the current date and time rather than the specified date and time. So the Python version of the command fails, but the GUI version works. This is extremely frustrating when I am trying to write code to create a transmittal file that documents all the daily or monthly data changes and sends it to our data partners.
Tested today in 10.5 and this is still a bug.