411 lines
24 KiB
Python
411 lines
24 KiB
Python
#!/usr/bin/env python3
|
||
"""「这一页被放弃时通知对方删草稿」那三条腿的**入口侧**验收:连真库,不打真上游。
|
||
|
||
PYTHONPATH=. python3 scripts/check_embed_abandon.py
|
||
|
||
``check_embed_decide.py`` 里那一段钉的是发出去的那一句长什么样(地址、方法、请求体、
|
||
按号记的那本幂等账)。这一份只钉那一段管不到的几件事,而这几件恰好是 2026-10 那次
|
||
「人没保存就返回、草稿箱里也把草稿删了,对面那张草稿却始终没人删」的现场:
|
||
|
||
1. **新开的一页不许复用上一趟的旧账**。上一趟已经发起成一张单(``claim_job`` 非空)时,
|
||
发起页上新开的那一页必须拿到**另一趟**会话。复用旧账的代价不是多一行记录:
|
||
``_abandon_skip`` 头一条就以"这一趟已经发起成一张单了"为由把删除挡掉,而这一趟占的号、
|
||
对方按这个号建的那份草稿都是新的——界面上样样正常,对面那张草稿永远没人删。
|
||
2. **三条腿的入口真通到判据**:``POST /embed/abandon``(人没保存就返回)、
|
||
``POST /embed/link-draft`` + ``DELETE /draft/{id}``(存过草稿再去草稿箱删)、
|
||
``POST /job/{job}/delete``(「我的待办」上删掉一张还没发起流转的单)。挂接那一环
|
||
断在哪,删草稿那一句就永远只找得到"没有会话",而屏幕上一点动静都没有。
|
||
3. **该不发的别发**:已经发起成单的、从一张已经存在的单上打开的、这一格自己关掉的、
|
||
还挂着一份没删的草稿的。删错比不删贵——那是一份还在用的草稿。
|
||
4. **没人报那一句时兜底要补上**:会话过期又没人报(关页签那一刻请求被浏览器掐掉、进程被杀),
|
||
``sweep_abandons`` 补发一次,而且只补一次。
|
||
5. **默认跟着那条源**:格子上一个勾都没勾,只要那条「可嵌入页面」上配了往哪儿发,就照发。
|
||
6. **删单那一条腿与删草稿那一条发的是同一句**:同一条地址、同一个方法、同一个号字段,
|
||
号取这张单的单号(草稿占下的那个号在发起那一刻原样交给这张单)。同一次删除里几条会话
|
||
报的是同一个号,对面只该听见一次;还挂着一份没删的草稿的那一趟不归这条腿管。
|
||
|
||
出站那一句不发往真上游:``fetch.http_request`` 换成本地记一笔的假上游。跑完连自己造的
|
||
那条源、那几趟会话、那三份草稿、那张流程与表单与留痕一起删掉。
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
import json
|
||
import pathlib
|
||
import sys
|
||
import time
|
||
from datetime import datetime, timedelta
|
||
|
||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent.parent))
|
||
|
||
from sqlalchemy import delete, select # noqa: E402
|
||
from starlette.testclient import TestClient # noqa: E402
|
||
|
||
from app import models # noqa: E402
|
||
from app.db import SessionLocal # noqa: E402
|
||
from app.engine import definition as definition_module # noqa: E402
|
||
from app.engine import engine # noqa: E402
|
||
from app.main import app # noqa: E402
|
||
from app.security import create_access_token # noqa: E402
|
||
from app.service import embed, embed_session # noqa: E402
|
||
|
||
#: 这一趟专用的那条「可嵌入页面」上配的删除地址(真上游不在这里打)
|
||
DELETE_URL = "https://abandon.invalid/api/drafts/by-flow-number"
|
||
#: 对面那个号字段的叫法:故意配成 ``no``,与默认那个 ``oa_flow_number`` 区分开,
|
||
#: 好证明"发出去的是配的那一条"而不是默认那一条
|
||
NUMBER_FIELD = "no"
|
||
#: 用它跑这一趟的人:本部署的默认管理员,草稿与发起都归他自己
|
||
PERSON = "1"
|
||
|
||
PASSED = 0
|
||
FAILS: list[str] = []
|
||
#: 假上游收到的那几笔:``(号, 方法, 地址, 请求体)``
|
||
SENT: list[tuple[str, str, str, dict]] = []
|
||
|
||
|
||
def check(label: str, condition, detail: str = "") -> None:
|
||
global PASSED
|
||
if condition:
|
||
PASSED += 1
|
||
print(f"[通过] {label}")
|
||
else:
|
||
FAILS.append(label)
|
||
print(f"[FAIL] {label}{f' -> {detail}' if detail else ''}")
|
||
|
||
|
||
def sends_for(number: str) -> list[tuple[str, str, str]]:
|
||
"""发往假上游、报的是这个号的哪几笔。按号筛:这一趟跑的时候库里可能正躺着别人的会话,
|
||
``sweep_abandons`` 会连它们一起扫,只数自己那个号才不会被别人的账干扰。"""
|
||
return [item for item in SENT if item[0] == number]
|
||
|
||
|
||
def fake_request(method, url, payload, headers, timeout, *args, **kwargs): # noqa: ANN001
|
||
body = payload if isinstance(payload, (bytes, bytearray)) else str(payload or "").encode()
|
||
try:
|
||
parsed = json.loads(body or b"{}")
|
||
except ValueError:
|
||
parsed = {}
|
||
SENT.append((str(parsed.get(NUMBER_FIELD) or ""), str(method), str(url), parsed))
|
||
return 200, '{"ok":true}'
|
||
|
||
|
||
def make_source(client: TestClient, headers: dict) -> str:
|
||
"""建一条这一趟专用的 embed 源。地址走 ORM 直接落列:这一趟要的是那三列的语义,
|
||
设计接口那一层的字段映射有它自己的校验脚本(``DataSourceView.spec.ts`` 那一路)。"""
|
||
code = f"abandon_chk_{int(time.time())}"
|
||
response = client.post("/api/v1/design/data-sources", headers=headers, json={
|
||
"code": code, "name": "放弃通知校验·对面新建页", "system": "ERP", "kind": "fetch",
|
||
"provider": "embed", "url": "https://abandon.invalid/new?no={arg.no}"})
|
||
return code if response.status_code < 400 else ""
|
||
|
||
|
||
def open_trip(db, row, *, key: str, follow_source: bool = True, **kw):
|
||
"""开一趟会话,快照与线上 ``POST /embed/launch`` 交的是同一份东西。
|
||
|
||
``follow_source=False`` 那一支交 ``{"abandon": False}``:这一格自己表态关掉。
|
||
"""
|
||
cfg = {} if follow_source else {"abandon": False}
|
||
field = {"key": key, "embed": cfg}
|
||
session, _ = embed_session.open_session(
|
||
db, row=row, field_key=key, field=field, person=PERSON,
|
||
abandon=embed.abandon_of(field, row, db), **kw)
|
||
db.commit()
|
||
return session
|
||
|
||
|
||
def build_process(db, stamp: str) -> tuple[str, str]:
|
||
"""一张最小的流程(开始 → 结束)。第三条腿只要一张「停在开始环节、没发起」的单。
|
||
|
||
回 ``(流程 id, 表单 id)``。开始环节不配任何东西:判据只看这一单有没有离开开始环节。
|
||
"""
|
||
form = models.FormElement(
|
||
name=f"放弃通知校验表单 {stamp}", alias=f"abdnchk-{stamp}",
|
||
content={"fields": [{"key": "reason", "label": "事由", "type": "text"}]})
|
||
db.add(form)
|
||
db.flush()
|
||
process = models.Process(
|
||
name=f"放弃通知校验流程 {stamp}", alias=f"abdnchk-{stamp}", latest_form=form.id,
|
||
latest_form_name=form.name, enabled=True, published=True, version=1,
|
||
approval_config={"skipStarter": False})
|
||
db.add(process)
|
||
db.flush()
|
||
begin = models.Activity(process=process.id, type="begin", name="开始", x=0, y=0,
|
||
order_number=0, config={})
|
||
end = models.Activity(process=process.id, type="end", name="结束", x=1, y=0,
|
||
order_number=1, config={})
|
||
db.add_all([begin, end])
|
||
db.flush()
|
||
db.add(models.Route(process=process.id, name="提交", from_activity=begin.id,
|
||
to_activity=end.id, order_number=0))
|
||
db.flush()
|
||
return process.id, form.id
|
||
|
||
|
||
def reload_session(db, prekey: str):
|
||
"""重新读一遍那一趟。接口那一路用的是另一个 Session,本进程这个事务的快照看不太到
|
||
它们刚写进去的东西(MySQL 的可重复读),读完先把自己这个事务收掉再读。"""
|
||
db.commit()
|
||
return embed_session.by_prekey(db, prekey)
|
||
|
||
|
||
def main() -> int:
|
||
db = SessionLocal()
|
||
client = TestClient(app, raise_server_exceptions=False)
|
||
token, _ = create_access_token(PERSON)
|
||
headers = {"Authorization": f"Bearer {token}"}
|
||
stamp = datetime.now().strftime("%m%d%H%M%S")
|
||
serials = [f"ABDN{stamp}{tail}" for tail in ("A1", "B2", "C3", "D4", "E5", "F6", "G7")]
|
||
draft_ids = [f"ABDNDRAFT{tail}" for tail in ("1", "2", "3")]
|
||
code = ""
|
||
marks = {"process": "", "form": "", "works": []}
|
||
real_request = embed_session.fetch.http_request
|
||
try:
|
||
code = make_source(client, headers)
|
||
check("建成了这条专用的「可嵌入页面」", bool(code), code)
|
||
if not code:
|
||
return 1
|
||
row = embed.get_source(db, code)
|
||
check("注册表上认得这条源(provider=embed 那一道闸过了)", row is not None, code)
|
||
if row is None:
|
||
return 1
|
||
row.abandon_url, row.abandon_method, row.abandon_field = DELETE_URL, "DELETE", NUMBER_FIELD
|
||
db.commit()
|
||
|
||
embed_session.fetch.http_request = fake_request # type: ignore[assignment]
|
||
try:
|
||
# ---------------- 1. 上一趟已发起,不该拖累新开的那一页 ----------------
|
||
old = open_trip(db, row, key="page_old", serial=serials[0])
|
||
claimed = embed_session.claim_by_prekey(db, old.prekey, PERSON,
|
||
job=f"ABDNJOB{stamp}1", serial=serials[0])
|
||
db.commit()
|
||
check("上一趟按「OA 自己点了发起」记上了账", claimed and
|
||
reload_session(db, old.prekey).status == models.EmbedSession.STATUS_CLAIMED)
|
||
|
||
fresh = open_trip(db, row, key="page_new", serial=serials[1])
|
||
check("新开的那一页拿到的是另一趟会话(没把已发起那一趟的旧账接过来)",
|
||
fresh.prekey != old.prekey, f"{fresh.prekey} vs {old.prekey}")
|
||
check("新开这一趟自己没开过张(claim_job 是空的)",
|
||
str(fresh.claim_job or "") == "", fresh.claim_job)
|
||
|
||
res = client.post("/api/v1/embed/abandon", headers=headers,
|
||
json={"prekeys": [fresh.prekey], "reason": "leave"}).json().get("data") or {}
|
||
check("POST /embed/abandon 真的把删除发出去了(人没保存就返回这一腿)",
|
||
res.get("notified") == 1 and len(sends_for(serials[1])) == 1, res)
|
||
check("发出去的是这一趟占的那个号,方法也是配的那个 DELETE",
|
||
bool(sends_for(serials[1])) and sends_for(serials[1])[0][1] == "DELETE"
|
||
and sends_for(serials[1])[0][2] == DELETE_URL, sends_for(serials[1]))
|
||
check("账上记着这一腿是 leave(几条腿同一本账,得分得清是谁发的)",
|
||
embed_session.abandon_record_of(reload_session(db, fresh.prekey)).get("reason")
|
||
== "leave")
|
||
|
||
res = client.post("/api/v1/embed/abandon", headers=headers,
|
||
json={"prekeys": [old.prekey], "reason": "leave"}).json().get("data") or {}
|
||
check("已经发起成单的那一趟放弃时不发(那张单还在,删了就是把在用的删了)",
|
||
res.get("notified") == 0
|
||
and (res.get("results") or [{}])[0].get("status") == "skipped"
|
||
and not sends_for(serials[0]), res)
|
||
|
||
# 最后这一条钉的是这一趟要防的那个失效**本身**:按旧口径(不带号、已认领的那一份
|
||
# 也算还开着)去找,拿到的就是已发起那一趟,而它头上那句 skip 就是"删除怎么都
|
||
# 发不出去"的全部原因——当时界面上样样正常,对面那张草稿躺了一整天
|
||
legacy = embed_session.find_open(db, source=code, person=PERSON, field="page_old",
|
||
reuse_claimed=True)
|
||
blocked = embed_session._abandon_skip(db, legacy) if legacy is not None else ""
|
||
check("旧口径拿到的正是已发起那一趟,而它被「已经发起成一张单」挡下(这就是当时的来路)",
|
||
legacy is not None and legacy.prekey == old.prekey and "已经发起成一张单" in blocked,
|
||
(legacy and legacy.prekey, blocked))
|
||
|
||
# ---------------- 2. 该不发的那几样 ----------------
|
||
closed = open_trip(db, row, key="page_closed", follow_source=False, serial=serials[2])
|
||
check("格子上自己写了 abandon=false 时不发(跟着源之外还留着单独关的口子)",
|
||
embed.abandon_wanted({"key": "page_closed", "embed": {"abandon": False}},
|
||
row, db) is False
|
||
and client.post("/api/v1/embed/abandon", headers=headers,
|
||
json={"prekeys": [closed.prekey]}).json()["data"]["notified"] == 0
|
||
and not sends_for(serials[2]))
|
||
|
||
on_work = open_trip(db, row, key="page_on_work", work=f"ABDNWORK{stamp}",
|
||
job=f"ABDNJOBX{stamp}", serial="")
|
||
res = client.post("/api/v1/embed/abandon", headers=headers,
|
||
json={"prekeys": [on_work.prekey]}).json().get("data") or {}
|
||
check("从一张已经存在的单上打开的那一趟不发(这一页属于那张单,不是一趟新草稿)",
|
||
res.get("notified") == 0 and (res.get("results") or [{}])[0].get("status")
|
||
== "skipped", res)
|
||
|
||
# ---------------- 3. 存了草稿:放弃不发,删草稿才发 ----------------
|
||
draft = models.Draft(id=draft_ids[0], title="放弃通知校验草稿", process="放弃通知校验",
|
||
process_name="放弃通知校验", person=PERSON, person_name="校验",
|
||
serial=serials[3], identity="", unit="")
|
||
db.add(draft)
|
||
db.flush()
|
||
drafting = open_trip(db, row, key="page_draft", draft=draft.id, serial=serials[3])
|
||
res = client.post("/api/v1/embed/abandon", headers=headers,
|
||
json={"prekeys": [drafting.prekey]}).json().get("data") or {}
|
||
check("挂着草稿的那一趟,页面放弃这一腿不发(OA 这边草稿还在用)",
|
||
res.get("notified") == 0 and not sends_for(serials[3]), res)
|
||
gone = client.delete(f"/api/v1/draft/{draft.id}", headers=headers)
|
||
check("DELETE /draft/{id} 那一刻把「对面那张也删了」发了出去(草稿箱删草稿这一腿)",
|
||
gone.status_code < 400 and len(sends_for(serials[3])) == 1,
|
||
f"{gone.status_code} {sends_for(serials[3])}")
|
||
check("账上记着这一腿是 draft-deleted",
|
||
embed_session.abandon_record_of(reload_session(db, drafting.prekey)).get("reason")
|
||
== "draft-deleted")
|
||
|
||
# ---------------- 4. 先占号再存草稿:靠 link-draft 挂上 ----------------
|
||
draft2 = models.Draft(id=draft_ids[1], title="放弃通知校验草稿二号", process="放弃通知校验",
|
||
process_name="放弃通知校验", person=PERSON, person_name="校验",
|
||
serial=serials[4], identity="", unit="")
|
||
db.add(draft2)
|
||
db.flush()
|
||
later = open_trip(db, row, key="page_later", serial=serials[4])
|
||
linked = client.post("/api/v1/embed/link-draft", headers=headers,
|
||
json={"prekeys": [later.prekey], "draft": draft2.id}
|
||
).json().get("data") or {}
|
||
check("存草稿那一刻挂上了那一趟(POST /embed/link-draft)",
|
||
linked.get("linked") == 1
|
||
and str(reload_session(db, later.prekey).draft or "") == draft2.id, linked)
|
||
gone = client.delete(f"/api/v1/draft/{draft2.id}", headers=headers)
|
||
check("挂接之后再删草稿,那一句照样发得出去(发的是草稿上那个号)",
|
||
gone.status_code < 400 and len(sends_for(serials[4])) == 1,
|
||
f"{gone.status_code} {sends_for(serials[4])}")
|
||
|
||
# ---------------- 5. 同一个人刷新还是那一趟 ----------------
|
||
again = open_trip(db, row, key="page_new", serial=serials[1])
|
||
check("同一个号再开一次还是那一趟(刷新三次不该在对面生出三张草稿)",
|
||
again.prekey == fresh.prekey, f"{again.prekey} vs {fresh.prekey}")
|
||
|
||
# ---------------- 6. 没人报那一句时,过期兜底补一次 ----------------
|
||
stale = open_trip(db, row, key="page_sweep", serial=serials[5])
|
||
stale.expires_at = datetime.now() - timedelta(seconds=60)
|
||
db.commit()
|
||
embed_session.sweep_abandons(db)
|
||
check("过期又没人报的那一趟由 sweep_abandons 补发一次",
|
||
len(sends_for(serials[5])) == 1
|
||
and embed_session.abandon_record_of(reload_session(db, stale.prekey)).get("reason")
|
||
== "expired", sends_for(serials[5]))
|
||
embed_session.sweep_abandons(db)
|
||
check("补过就不再补第二遍(对面那条删除接口不该被自家清扫一遍遍撞)",
|
||
len(sends_for(serials[5])) == 1, sends_for(serials[5]))
|
||
|
||
# ---------------- 7. 还没发起的单被删掉:第三条腿 ----------------
|
||
marks["process"], marks["form"] = build_process(db, stamp)
|
||
actor = engine.Actor.from_ref(db, db.get(models.User, PERSON))
|
||
held = engine.create_job(db, process_id=marks["process"], actor=actor,
|
||
data={"reason": "删单通知校验"}, serial=serials[6],
|
||
title="放弃通知校验·停在开始环节", hold_at_begin=True)
|
||
assert held.work is not None, "这张单当场就流转出去了,第三条腿没得测"
|
||
work_id, work_job = held.work.id, held.work.job
|
||
marks["works"] = [work_id]
|
||
# 同一趟在库里的四种形状:先占号那一条、被这张单认领走的那一条、从这张单上
|
||
# 又开一次的那一条,以及还挂着一份没删的草稿的那一条(最后这条不该被带上)
|
||
pre_open = open_trip(db, row, key="page_w_pre", serial=serials[6])
|
||
claimed_leg = open_trip(db, row, key="page_w_claim", serial=serials[6])
|
||
embed_session.claim_by_prekey(db, claimed_leg.prekey, PERSON,
|
||
job=work_job, serial=serials[6])
|
||
keeper = open_trip(db, row, key="page_w_draft", serial=serials[6],
|
||
draft=draft_ids[2])
|
||
on_work = open_trip(db, row, key="page_w_work", work=work_id, job=work_job)
|
||
draft3 = models.Draft(id=draft_ids[2], title="放弃通知校验草稿三号",
|
||
process="放弃通知校验", process_name="放弃通知校验",
|
||
person=PERSON, person_name="校验", serial=serials[6],
|
||
identity="", unit="")
|
||
db.add(draft3)
|
||
db.commit()
|
||
matched = {item.prekey for item in embed_session.work_abandon_sessions(db, held.work)}
|
||
check("这一趟的四种形状都认得出是这张单的(占号 / 认领 / 从单上打开)",
|
||
{pre_open.prekey, claimed_leg.prekey, keeper.prekey,
|
||
on_work.prekey} <= matched, sorted(matched))
|
||
gone = client.post(f"/api/v1/job/{work_job}/delete", headers=headers, json={})
|
||
# 接口那条 Session 已经提交,本进程这个事务的快照还停在删除之前;先收掉再读
|
||
db.commit()
|
||
check("DELETE 一张还没发起的单办成了(删单这一腿的入口通到判据)",
|
||
gone.status_code < 400 and db.get(models.Work, work_id) is None,
|
||
f"{gone.status_code} {gone.json()}")
|
||
sends = sends_for(serials[6])
|
||
check("删单这一刻给对方发了那一句,报的是这张单的单号",
|
||
len(sends) == 1 and sends[0][0] == serials[6], sends)
|
||
draft_sends = sends_for(serials[3])
|
||
check("发出去的方法、地址与请求体那几栏,与删草稿那一条腿配的是同一份",
|
||
bool(sends) and bool(draft_sends)
|
||
and sends[0][1] == draft_sends[0][1] == "DELETE"
|
||
and sends[0][2] == draft_sends[0][2] == DELETE_URL
|
||
and sorted(sends[0][3]) == sorted(draft_sends[0][3]) == [NUMBER_FIELD],
|
||
(sends, draft_sends))
|
||
db.commit()
|
||
checked = {row_item.prekey: embed_session.abandon_record_of(
|
||
reload_session(db, row_item.prekey))
|
||
for row_item in (pre_open, claimed_leg, on_work, keeper)}
|
||
check("同一个号在一次删除里只通知一次(几条会话报的是同一个号)",
|
||
sum(1 for item in checked.values() if item.get("status") == "ok") == 1,
|
||
{key: (value.get("status"), value.get("serial"))
|
||
for key, value in checked.items()})
|
||
check("账上记着这一腿是 work-deleted,记的号是这张单的单号",
|
||
checked[pre_open.prekey].get("reason") == "work-deleted"
|
||
and str(checked[pre_open.prekey].get("serial") or "") == serials[6],
|
||
checked[pre_open.prekey])
|
||
traces = db.execute(
|
||
select(models.DataSourceLog).where(
|
||
models.DataSourceLog.source == code,
|
||
models.DataSourceLog.kind == "abandon",
|
||
models.DataSourceLog.message.contains(serials[6]))
|
||
).scalars().all()
|
||
check("数据源留痕里这一行按单号查得到,也写着是哪条腿发的(排查时只有号对得上)",
|
||
bool(traces) and "work-deleted" in traces[0].message,
|
||
[item.message for item in traces])
|
||
check("留痕上写着是谁删的(引擎交上来的那份身份只有 person_name,别留一栏空的)",
|
||
bool(traces)
|
||
and traces[0].actor_name == str(db.get(models.User, PERSON).display_name),
|
||
[(item.actor, item.actor_name) for item in traces])
|
||
check("还挂着一份没删的草稿的那一趟没被这条腿带上(那份草稿人还要用)",
|
||
not checked[keeper.prekey], checked[keeper.prekey])
|
||
check("删单之后那张单在库里真的没了,第三方那边的账也翻篇了",
|
||
db.get(models.Work, work_id) is None
|
||
and str(reload_session(db, claimed_leg.prekey).claim_job or "") == "")
|
||
finally:
|
||
embed_session.fetch.http_request = real_request # type: ignore[assignment]
|
||
finally:
|
||
purge(db, code, draft_ids, marks)
|
||
db.close()
|
||
|
||
for line in FAILS:
|
||
print(f"[FAIL] {line}")
|
||
if FAILS:
|
||
print(f"共 {len(FAILS)} 条不对")
|
||
return 1
|
||
print(f"通过:放弃、删草稿、删单这三条腿都通到判据,该发的一条没漏、该挡的一条没多({PASSED} 项)")
|
||
return 0
|
||
|
||
|
||
def purge(db, code: str, draft_ids: list[str], marks: dict) -> None:
|
||
"""删掉自己造的那条源、那几趟会话、那三份草稿、那张流程与表单与留痕,别的一律不碰。"""
|
||
db.commit()
|
||
if draft_ids:
|
||
db.execute(delete(models.Draft).where(models.Draft.id.in_(draft_ids)))
|
||
if marks.get("works"):
|
||
for model in (models.Task, models.TaskCompleted, models.WorkLog, models.Read,
|
||
models.ReadCompleted, models.WorkComment, models.Attachment,
|
||
models.Notification, models.OutboundMessage, models.NodeDecision):
|
||
db.execute(delete(model).where(model.work.in_(marks["works"])))
|
||
db.execute(delete(models.Work).where(models.Work.id.in_(marks["works"])))
|
||
if marks.get("process"):
|
||
db.execute(delete(models.SerialNumber).where(
|
||
models.SerialNumber.process == marks["process"]))
|
||
db.execute(delete(models.ProcessSnapshot).where(
|
||
models.ProcessSnapshot.process == marks["process"]))
|
||
db.execute(delete(models.Route).where(models.Route.process == marks["process"]))
|
||
db.execute(delete(models.Activity).where(models.Activity.process == marks["process"]))
|
||
db.execute(delete(models.Process).where(models.Process.id == marks["process"]))
|
||
if marks.get("form"):
|
||
db.execute(delete(models.FormElement).where(models.FormElement.id == marks["form"]))
|
||
definition_module.forget_snapshots()
|
||
if code:
|
||
for model, column in ((models.EmbedSession, models.EmbedSession.source),
|
||
(models.DataSourceLog, models.DataSourceLog.source),
|
||
(models.DataSource, models.DataSource.code)):
|
||
db.execute(delete(model).where(column == code))
|
||
db.commit()
|
||
|
||
|
||
if __name__ == "__main__":
|
||
sys.exit(main())
|