CreateVersion & DeleteVersion both fail on workspace errors

346
3
09-15-2021 08:31 AM
Jesse
by
New Contributor II

I have a workflow in which I need to iteratively delete and re-create versions for automated edits. When I run the script, I do not get any errors and everything works fine; however, as soon as someone else runs the script, they cannot get past the version management steps. Here's the relevant code:

from arcpy import (ClearWorkspaceCache_management,
                   CreateDatabaseConnection_management,
                   CreateVersion_management, DeleteVersion_management)
def clear_cache(func):
    """Clears the workspace cache.

    Used as a decorator on any function that deals with version management.
Parameters ---------- func : function The decorated function """ def wrapper(*args, **kwargs): log.debug("Clearing workspace cache...") ClearWorkspaceCache_management() value = func(*args, **kwargs) return value return wrapper


@clear_cache def versioned_connection(parent: str, version_name: str): """Create a version and associated versioned database connection. Parameters ---------- parent : str The parent of the edit version to be created version_name : str The name of the version to be created Returns ------- str A file path to the proper connection file """ conn_file = os.path.join(".\\.esri", f"{version_name}.sde") full_conn_path = os.path.realpath(conn_file) if os.path.exists(conn_file): log.debug(f"{version_name} has already been created...") else: version_owner = "GISSCR" full_version_name = f"{version_owner}.{version_name}" # Create the version log.debug((f"Creating a version called {version_name} owned by " f"{version_owner}...")) version = {"in_workspace": config.edit, "parent_version": parent, "version_name": version_name, "access_permission": "PRIVATE"} CreateVersion_management(**version) # Create the database connection file log.debug(f"Creating a versioned db connection at {conn_file}...") connect = {"out_folder_path": ".\\.esri", "out_name": f"{version_name}.sde", "version": full_version_name, "password": "password",
"database_platform": "SQL_SERVER", "instance": "GISData", "database": "gisprod3", "account_authentication": "DATABASE_AUTH", "username": "gisscr", "version_type": "TRANSACTIONAL"}
CreateDatabaseConnection_management(**connect)

return full_conn_path


@clear_cache def
delete_versions(connection: str) -> None:
"""Deletes versions created for editing Facility IDs

Parameters
----------
connection : str
location of the sde connection file """

del_versions = [v for v in ListVersions(connection) if "FACILITYID" in v.upper()]
for d in del_versions:
DeleteVersion_management(connection, d)
if name == "__main__":
# Step 1: Delete all existing Facility ID versions
log.info("Deleting old Facility ID versions...")
edit = "path\to\edit\connection"
delete_versions(edit)

# Step 2: Re-create FacilityID versions
log.info("Creating new Facility ID versions...")
parent = "SDE.DEFAULT"
v_name = "FacilityID_Edits"
conn_file = versioned_connection(parent, v_name) 

These version management steps always fail for other people, even though I've written a function that clears the workspace cache before every version management step (as suggested here). It never fails for me, though (even on different machines!!) This is the traceback when it fails:

09/14/2021 16:21:36.316 : __main__ : ERROR : Something prevented the script from running
Traceback (most recent call last):
  File "S:\PW\PWShare\GIS\SharedScripts\facilityid\facilityid\__main__.py", line 10, in <module>
    app.main()
  File "S:\PW\PWShare\GIS\SharedScripts\facilityid\facilityid\app.py", line 52, in main
    conn_file = mgmt.versioned_connection(parent, v_name)
  File "S:\PW\PWShare\GIS\SharedScripts\facilityid\facilityid\utils\management.py", line 152, in versioned_connection
    CreateVersion_management(**version)
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 22237, in CreateVersion
    raise e
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 22234, in CreateVersion
    retval = convertArcObjectToPythonObject(gp.CreateVersion_management(*gp_fixargs((in_workspace, parent_version, version_name, access_permission), True)))
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 511, in <lambda>
    return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000837: The workspace is not the correct workspace type.
WARNING 000379: The value may not be valid because of empty domain or does not exist in the domain
Failed to execute (CreateVersion).

I'm at my wit's end. Plz help!

Tags (2)
0 Kudos
3 Replies
MichaelVolz
Esteemed Contributor

What is the value of  full_conn_path for you compared to other users?  Maybe add a print statement to your code to see if this value is applicable to all users or just you for your current code.

 

0 Kudos
Jesse
by
New Contributor II

Good suggestion, I'll give it a whirl and see if it leads me anywhere.

0 Kudos
Jesse
by
New Contributor II

The paths are identical across all folks running the script, me included.

0 Kudos