Select to view content in your preferred language

Cannot add/remove attachments in python when table/featureclass is versioned

2132
2
Jump to solution
12-07-2012 08:33 AM
by Anonymous User
Not applicable
Hello all,

Has anyone run into problems when using the arcpy.AddAttachments_management() function with tables that have been registered as versioned? I can't seem to successfully do it...even though attachments work fine through other means (e.g., via a REST interface for a FeatureServer).

In my specific case, I have an enterprise sde geodatabase (using PostgreSQL). Before anything gets registered as versioned, I can add attachments as usual. Once things are versioned, however, it's a different story. Here's the easiest way for me to summarize this:

 # Works arcpy.AddAttachments_management("C:/test/test.sde/test.sde.test_table","objectid","C:/test/test.csv","FileID","FilePath","#")  # Cleanup arcpy.RemoveAttachments_management("C:/test/test.sde/test.sde.test_table","objectid","C:/test/test.csv","FileID","#")  # Register the table as versioned: arcpy.RegisterAsVersioned_management("C:/test/test.sde/test.sde.test_table")  # Produces this error: http://resources.arcgis.com/en/help/main/10.1/00vp/00vp0000002n001180.htm arcpy.AddAttachments_management("C:/test/test.sde/test.sde.test_table","objectid","C:/test/test.csv","FileID","FilePath","#")  # Unregister the table as versioned: arcpy.UnregisterAsVersioned_management("C:/test/test.sde/test.sde.test_table")  # Still produces this error: http://resources.arcgis.com/en/help/main/10.1/00vp/00vp0000002n001180.htm arcpy.AddAttachments_management("C:/test/test.sde/test.sde.test_table","objectid","C:/test/test.csv","FileID","FilePath","#")  # Oops, looks like the __ATTACH table is still versioned (gets registered automatically, but not unregistered) # Note: if I only unregister the __ATTACH table, then the table it is associated with does get automatically unversioned. arcpy.UnregisterAsVersioned_management("C:/test/test.sde/test.sde.test_table__ATTACH")  # Now this works again: arcpy.AddAttachments_management("C:/test/test.sde/test.sde.test_table","objectid","C:/test/test.csv","FileID","FilePath","#") 


If I have the same table/featureclass accessible through an editable feature service, the addattachments REST calls work fine, and respect versioning. This problem seems to be limited to only python. As a workaround, I guess I can manually insert records into the __ATTACH table...is this a bad idea? This seems to work okay:

 edit = arcpy.da.Editor("C:/test/test.sde") edit.startEditing(False, True) edit.startOperation()  cur = arcpy.da.InsertCursor("C:/test/test.sde/test.sde.test_table__ATTACH",["rel_objectid","content_type","att_name","data_size","data"]) file = memoryview(open("C:/test/test.pdf","rb").read()) row = [801,"application/pdf","test.pdf",len(file.tobytes()),file] cur.insertRow(row)  edit.stopOperation() edit.stopEditing(True) 


After performing the above, everything else (e.g., a FeatureServer) seems to recognize the attachments without any noticeable problem. Is it a bad idea to do this as a workaround? My interpretation is that all the add/remove features tools do is modify the contents of the __ATTACH tables, so it seems like inserting rows like the above should be safe to do.

Any thoughts/suggestions?
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JillianPenney
Esri Contributor
I also looked into this issue and was able to repro it using the GP tools as well. It seems that when you register the input dataset as versioned, the __ATTACH table becomes registered as versioned too (because it is in a relationship class with the input dataset). However, when the the input dataset is unregistered as versioned, the __ATTACH table is not automatically unregistered as versioned. This conflict seems to be causing the error.

Another work around you could use is to manually unregister the __ATTACH table by right clicking>unregister as versioned or using arcpy.UnregisterAsVersioned_management() in your script.

View solution in original post

0 Kudos
2 Replies
JakeSkinner
Esri Esteemed Contributor
Hi Mike,

It looks like you may have discovered a bug.  I was able to reproduce the same behavior using ArcGIS 10.1 SP1 and SQL Server.  I would recommend following up with Tech Support to verify this, and to have this bug logged with your customer information attached to it.

As for your workaround, I don't see any problems using this.  I ran a test and everything appeared to work.  I also verified that the delta (A & D) tables update correctly, as well as the SDE_STATES table.
0 Kudos
JillianPenney
Esri Contributor
I also looked into this issue and was able to repro it using the GP tools as well. It seems that when you register the input dataset as versioned, the __ATTACH table becomes registered as versioned too (because it is in a relationship class with the input dataset). However, when the the input dataset is unregistered as versioned, the __ATTACH table is not automatically unregistered as versioned. This conflict seems to be causing the error.

Another work around you could use is to manually unregister the __ATTACH table by right clicking>unregister as versioned or using arcpy.UnregisterAsVersioned_management() in your script.
0 Kudos