* fix(postgres): add rollback to prevent crash on hash collision
* fix(postgres): rollback to savepoint to prevent crash on hash collision
* fix(postgres): tighten bounds for a rollback to savepoint for a better perf
* fix(postgres): Handle hash collision efficiently with ON CONFLICT
* refactor: better naming
- Private methods
- "rows" is not a correct name for single record's name
* fix: Bad error handling
- Why raise postgres error?
- Let default error raising/handling happen
---------
Co-authored-by: Ankush Menat <ankush@frappe.io>
The `check_parent_permission` calls in client.py are redundant because
`frappe.has_permission` already handles child tables via `has_child_permission`,
which performs the same validations plus additional permlevel checks.
Adjust to use `ON CONFLICT` in a similar manner as the others
```
File "apps/frappe/frappe/model/rename_doc.py", line 192, in rename_doc
update_user_settings(old, new, link_fields)
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
File "apps/frappe/frappe/model/rename_doc.py", line 276, in update_user_settings
sync_user_settings()
~~~~~~~~~~~~~~~~~~^^
File "apps/frappe/frappe/model/utils/user_settings.py", line 52, in sync_user_settings
frappe.db.multisql(
^^^^^^^^^^^^^^^^^^^
...<12 lines>...
as_dict=1,
File "apps/frappe/frappe/database/database.py", line 1416, in multisql
return self.sql(query, values, **kwargs)
~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
File "apps/frappe/frappe/database/sqlite/database.py", line 454, in sql
return super().sql(*args, **kwargs)
~~~~~~~~~~~^^^^^^^^^^^^^^^^^
File "apps/frappe/frappe/database/database.py", line 272, in sql
self.execute_query(query, values)
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
File "apps/frappe/frappe/database/sqlite/database.py", line 443, in execute_query
return self._cursor.execute(query, values or ())
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 3, and there are 4 supplied.
```
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
If `db_query_compat=True` (set by `qb_query.py`), then we default to some `db_query.py` behaviour.
Otherwise, we'll retail the previous query builder behaviour, this is to minimize breakage on either side.
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
* fix: clear cache and prevent data access after DocType deletion
* fix: Handle potential DB failures during migrate
---------
Co-authored-by: Ankush Menat <ankush@frappe.io>
The previous update broke systems where DocTypes exist that contains names like Union or Select
(cherry picked from commit f997d40c56d717693c66a8b7e69d12462a673ede)