* feat: global `frappe.in_test` flag
* feat: helper utility to toggle `frappe.in_test`
* fix: use `toggle_test_mode` util
* fix: use `frappe.in_test`
* chore: add comment explaining global `in_test`
* chore: ignore commit replacing flag usage
* test: temporarily disable `frappe.in_test`
this worked earlier because flag was set in werkzeug.local which was separate for API test client
* test: add comment explaining change
* fix: Avoid Snapshot violation
- Main thread created and "read" user
- Other thread modified something
- Main thread wants to delete or "write" to same row.
This violates snapshot isolation.
* fix: treat snapshot violation as deadlock for now
* test: handle snapshot violations
* feat: hook `ignore_links_on_delete` to skip doctypes on delete
* fix: helper comment
* fix: helper comment
* test: test case for `ignore_links_on_delete`
* test: fix test case
refactor: clean up code to py39+ supported syntax
- f-strings instead of format
- latest typing support instead of pre 3.9 TitleCase
- remove UTF-8 declarations.
- many more changes
Powered by https://github.com/asottile/pyupgrade/ + manual cleanups
When you create a Virtual DocType as a Child Table (which is possible without any warning), then it will lead to several errors when updating or deleting of the parent document.
This is because the following files just execute a SQL Statement for the doctype (which doesnt have a DB Table, as this is the nature of a virtual doctype ;-)
**apps/frappe/frappe/model/document.py**
```py
frappe.db.sql("""delete from `tab{0}` where parent=%s and parenttype=%s and parentfield=%s""".format(df.options), (self.name, self.doctype, fieldname))
```
**apps/frappe/frappe/model/delete_doc.py**
```py
frappe.db.sql(
"delete from `tab%s` where parenttype=%s and parent = %s" % (t, "%s", "%s"), (doctype, name)
)
```
So at these points, I added a check to not perform any sql command for virtual doctypes. With these changes, my affected situation is solved. Perhaps there are other situations, I didn't encounter yet.
As an additional feature, those virtual doctype models should also get an information about the parent is deleted, to propagate the deletion to the remote data pools; but for now I hope this bugfix can be approved.
If someone deletes doctype and restores it back all customization are
lost, there's no "real" reason to delete all these customization. They
are only ever active if the doctype is being used.
Explanations:
- Custom field: is used by meta when doctype meta is requested, if meta
isn't requested then custom field is effectively inactive.
- Client script: loaded by meta when doctype is requested by desk. So
inactive in deleted state.
- Property setter: loaded by meta, so inactive when doctype isn't
present.
- Report: will break doctype isn't present, but user should delete them
manually to avoid loss of "scripts" or anything special they might
have done. Also report's doctype don't 100% indicate that it's based
solely on that doctype.
* feat: utility methods for docstatus
* refactor: use utility method for doctsatus
* refactor: enum for docstatus
* refactor: docstatus as property
* fix: set docstatus
* feat: docstatus extends int class
* test: docstatus of BaseDocument
* refactor: occurrences of docstatus
* fix: typo
* refactor: move docstatus to a separate file
* test: docstatus
* fix: sider
The license.txt file has been replaced with LICENSE for quite a while
now. INAL but it didn't seem accurate to say "hey, checkout license.txt
although there's no such file". Apart from this, there were
inconsistencies in the headers altogether...this change brings
consistency.
Use frappe.db.delete wherever possible. Get rid of all the frappe.db.sql ;)
This commit focuses on the pending modules that had relatively easier
DELETE statements.