ArcPy Safe Edits
Editing an enterprise geodatabase is not editing a file. Versioning, locks, and related data make "just run an UpdateCursor" a way to corrupt production. Edit safely.
Use an edit session
- Wrap edits in
arcpy.da.Editor(workspace)withstartEditing()/startOperation(). An edit session is required for versioned data, and for data participating in topologies, geometric/utility networks, relationship classes, or attribute rules. - Choose the right mode:
startEditing(with_undo, multiuser_mode)—multiuser_mode=Truefor versioned SDE,Falsefor nonversioned. - On error,
abortOperation()/stopEditing(save_changes=False); onlystopEditing(True)after success. Wrap in try/except so a failure rolls back instead of leaving a half-applied edit.
Manage cursors and locks
- Use
arcpy.da.UpdateCursor/InsertCursorinside the edit session, always with awithblock (ordelthe cursor) so it releases its lock. A leaked cursor holds a lock that blocks every other editor. - Don't hold a schema lock longer than needed; ensure no ArcGIS Pro session or other process has the dataset open when you need exclusive access.
Respect versioning
- Edit the correct version, not
DEFAULTdirectly in a multiuser workflow. Understand the reconcile/post cycle; leave reconcile/post andCompressto the established workflow (often a DBA task), don't improvise them.
Respect data integrity
- Honor domains, subtypes, and attribute rules — writing an out-of-domain value or bypassing a rule corrupts data quietly.
- Test on a copy or a non-default version first. Never debug edit logic against production DEFAULT.
Why this matters
A naive cursor edit on versioned SDE can deadlock other editors, leave a half-applied transaction, or violate referential integrity across related classes — and the damage is multiuser and hard to undo. Edit sessions, scoped locks, and the right version turn risky writes into safe, atomic ones.