@@ -478,6 +478,7 @@ def update_draft_from_markdown(
478478 draft_section_id : int = None ,
479479 tags = None ,
480480 dry_run : bool = False ,
481+ allow_unsupported_change : bool = False ,
481482 ) -> dict :
482483 """
483484 Update an existing draft body from Markdown, with optional metadata changes.
@@ -497,12 +498,7 @@ def update_draft_from_markdown(
497498 if not isinstance (draft_body , dict ):
498499 raise ValueError ("Malformed draft body: draft_body must be a JSON object" )
499500
500- _ , unsupported_nodes = document_to_markdown (draft_body )
501- if unsupported_nodes :
502- raise ValueError (
503- "Refusing to update: remote draft contains unsupported Substack nodes. "
504- "Export it first or remove the nodes manually to avoid data loss."
505- )
501+ _ , remote_unsupported = document_to_markdown (draft_body )
506502
507503 post = Post (
508504 title = draft .get ("title" , "" ),
@@ -515,6 +511,25 @@ def update_draft_from_markdown(
515511 )
516512 post .from_markdown (markdown , api = self )
517513
514+ _ , submitted_unsupported = document_to_markdown (post .draft_body )
515+
516+ if not allow_unsupported_change :
517+ remote_serialized = [
518+ json .dumps (n , ensure_ascii = False , separators = ("," , ":" ), sort_keys = True )
519+ for n in remote_unsupported
520+ ]
521+ submitted_serialized = [
522+ json .dumps (n , ensure_ascii = False , separators = ("," , ":" ), sort_keys = True )
523+ for n in submitted_unsupported
524+ ]
525+ if sorted (remote_serialized ) != sorted (submitted_serialized ):
526+ raise ValueError (
527+ "Refusing to update: remote unsupported nodes are missing, duplicated, stale, or altered. "
528+ "Export the draft first or set allow_unsupported_change=True to proceed."
529+ )
530+
531+ unsupported_nodes = remote_unsupported
532+
518533 update_payload = {"draft_body" : json .dumps (post .draft_body )}
519534
520535 if subtitle is not None :
0 commit comments