Commit graph

63 commits

Author SHA1 Message Date
Sumit Jain
1d9eb802fc
feat: Enhance autoname functionality (#36827)
* feat: Enhance autoname functionality to support expression naming rules with and without dots before dashes

* style: Fix formatting issues

---------

Co-authored-by: Suraj Shetty <surajshetty3416@gmail.com>
2026-02-07 06:22:28 +00:00
Ankush Menat
ee56afade5
refactor!: Remove UUID Utils library (#36216)
potentially minor breaking change - removal of a default dependency.

Use inbuilt `uuid` library instead of relying on third party lib.

py3.14 adds support for uuidv7, so we no longer need third party lib.
2026-01-22 11:40:11 +00:00
Aarol D'Souza
15e59a3ba2
fix(postgres): add rollback to prevent crash on hash collision (#34686)
* 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>
2025-12-05 12:02:10 +05:30
Akhil Narang
8a758365eb
Revert "Merge pull request #28363 from frappe/expr-series" (#31202)
This reverts commit 91d553c9cf, reversing
changes made to d17136cd04.
2025-02-10 06:46:45 +00:00
Ankush Menat
9b79dfeb7b
perf: "random" naming to improve concurrency and locality (#30053)
This feels overengineered and it kinda is, but other efforts to
inroduce sequential naming/UUID naming haven't been that fruitful
either.

10 character random "hash" i now changed to.

1. first character - last character in UUID4 ID of request/job
2. three characters - derived from current timestamp.
4. 6 characters - random data.

This satisfies all three requirements:

1. Readers - temporal locality should result in spatial locality on disk. (fewer pages accessed)
2. Single writer - temporal locality should result in spatial locality. (fewer dirty pages)
3. Multiple writers - temporal locality should NOT result in spatial locality. (less lock contention)

Mostly concludes https://github.com/frappe/frappe/pull/25309 and https://github.com/frappe/frappe/pull/28349

Rough probabiliy numbers

Assumptions:
- Unique per worker prefix - 16 (uuid's base16 version)
- Rough time spent generating names - 10% of request (very very conservative estimate)

Probability(collision) = P(at least one prefix collision) * P(time collision)
Probability(collision) = (1 - p(all different)) * 10%
Probability(collision) = (1 - (16! / 16-N! )/ 16^N ) * 10%

| N (concurrency) | Probability(collision) |
| 1  |    0.0% |
| 2  |    0.6% |
| 3  |    1.8% |
| 4  |    3.3% |
| 5  |    5.0% |
| 6  |    6.6% |
| 7  |    7.9% |
| 8  |    8.8% |
2025-01-25 07:04:09 +00:00
Sumit Bhanushali
8233c2ffce fix: naming tests should consider pattern for generating series 2024-12-08 10:04:50 +05:30
Ankush Menat
16407a50ec
fix: Excessive gap locking from hash naming (#28349)
Because of large common prefix hash naming becomes "too sequential" when
doing a lot of concurrent writes.

I don't know a good tradeoff between both use cases:
1. Lots of reads - prefers large shared prefix.
2. Lots of writes - prefers small shared prefix.

But as of now this punishes writes too badly in form of excessive
locking. Until a better fix is found, it's better to keep it prefix free.

---

A better fix would be a tradeoff of between these two:

1. Reads - temporal locality should result in spatial locality on disk.
2. Writes - temporal locality should NOT result in spatial locality.

temporal locality = data inserted around same time
spatial locality = data sits next to each other in DB pages.

This can be achieved by adding a small request/job specific part to
prefix so each concurrent request has it's own different locality when
writing data.
2024-11-01 06:18:22 +00:00
David Arnold
c114e5fae8
refactor: unit vs integration treewide (#27992)
* refactor: constitute unit test case

* fix: docs and type hints

* refactor: mark presumed integration test cases explicitly

At time of writing, we now have at least two base test classes:

- frappe.tests.UnitTestCase
- frappe.tests.IntegrationTestCase

They load in their perspective priority queue during execution.

Probably more to come for more efficient queing and scheduling.

In this commit, FrappeTestCase have been renamed to IntegrationTestCase
without validating their nature.

* feat: Move test-related functions from test_runner.py to tests/utils.py

* refactor: add bare UnitTestCase to all doctype tests

This should teach LLMs in their next pass that the distinction matters
and that this is widely used framework practice
2024-10-06 09:43:36 +00:00
Ankush Menat
1e4c182b52
fix: retry count per doc instead of global (#26159) 2024-04-25 09:34:52 +00:00
Ankush Menat
1ec4d658fc fix: Allow setting UUID to application code 2024-03-29 19:02:28 +05:30
Ankush Menat
adf24b24d4
perf: use base32 space for random names instead of base16 (#25497) 2024-03-17 20:02:57 +05:30
Akhil Narang
3f1e19de85
refactor(treewide): enable RUF rules
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2024-02-21 16:20:28 +05:30
Ankush Menat
de9ac89748 style: re-format with ruff 2024-02-05 18:53:33 +05:30
barredterra
9d6cbd0c15 fix: typos 2024-01-24 02:41:03 +01:00
Deepesh Garg
e38078a69f
test: Patch hooks for testing (#21702)
* test: Patch hooks for testing

* test: hooks patcher

---------

Co-authored-by: Ankush Menat <ankush@frappe.io>
2023-07-17 12:41:27 +05:30
Deepesh Garg
e32e74f2f1
feat: Custom naming series parser via hooks (#21690)
* feat: Custom naming series parser via hooks

* chore: use assignment operatot

Co-authored-by: Ankush Menat <ankushmenat@gmail.com>

* test: Unit test for custom parser

* test: Unit test for custom parser

---------

Co-authored-by: Ankush Menat <ankushmenat@gmail.com>
2023-07-16 12:57:40 +05:30
Suraj Shetty
bd737d3616
Merge branch 'develop' into fix-note-2 2023-05-16 07:53:15 +05:30
Ritwik Puri
4bd32bcf04
fix: naming part should be empty if field is empty (#20978) 2023-05-14 00:41:12 +05:30
barredterra
913417e1dc fix: naming test cases
... that used to rely on title based naming of Note
2023-01-17 23:51:58 +01:00
Ankush Menat
95f67b8de8
fix: ignore empty part in naming series (#17508)
on v13 doc.get("") returns entire doc dictionary, this gets strigified
and becomes a problem for naming.
2022-07-14 13:14:58 +05:30
Ankush Menat
81b37cb7d2
refactor: clean up code to py310 supported features (#17367)
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
2022-07-01 11:51:05 +05:30
barredterra
ef3777badb test: refactor date naming test 2022-06-21 16:22:22 +02:00
vishdha
80de434984 chore: Test case added for datetime, date and time field 2022-06-17 20:07:14 +05:30
vishdha
754de9a56b fix: minor change added 2022-06-17 14:03:29 +05:30
vishdha
a9e222a706 chore: test case added for _auto_name format for date field 2022-06-17 13:59:21 +05:30
Ankush Menat
462aa20386
fix: naming using doc fields (#17040) 2022-05-31 19:55:34 +05:30
Ankush Menat
5590cb0be8 feat: NamingSeries class
Single class to group together everything required related to naming
series
2022-05-31 11:53:58 +05:30
Ankush Menat
5c35aae876 fix: accurate prefix parsing
Previous version of prefix parsing relied on partial reimplemntation of
naming series logic which was outdated and often incorrect.
2022-05-31 11:53:58 +05:30
Ankush Menat
ebcb568e9d test: making naming tests re-runnable
These were modifying TODO schema ._. WAD
2022-05-31 11:53:58 +05:30
Ankush Menat
a615c60be4 test: naming on child tables 2022-04-14 16:33:23 +05:30
Gavin D'souza
70a8a49c9c fix: new_doctype API testing util
Use kwargs instead of mapping defined kwargs to single actions
2022-04-12 19:06:35 +05:30
Suraj Shetty
c0c5b2ebdd
style: format all python files using black (#16453)
Co-authored-by: Frappe Bot <developers@frappe.io>
2022-04-12 10:59:25 +05:30
Ankush Menat
046f5d31af
fix: don't update autoname field when using Document.save (#16436) 2022-04-01 14:00:27 +05:30
phot0n
bebc8058b6 feat: integer primary keys 2022-03-11 23:46:00 +05:30
Rucha Mahabal
240665940f fix: remove redundant test record deletions and resetting 2022-02-09 11:01:05 +05:30
Rucha Mahabal
78e606bd0f
Merge branch 'develop' into fix-naming-validation 2022-02-09 10:52:24 +05:30
Mohammad Hasnain Mohsin Rajan
4ff86e1d63
revert: "refactor: set amended docname to original docname" (#15867)
* Revert: "refactor: set amended docname to original docname"

80d111baf2.

* test: test if amended doc has different name
2022-02-04 17:22:18 +05:30
Rucha Mahabal
62331fcba3 test: validation for no name specified 2022-01-31 13:49:37 +05:30
Rucha Mahabal
66c8fb9cfa fix: validate doc naming when set via prompt or by passing set_name 2022-01-27 12:24:22 +05:30
Daniel Gerhardt
16dca0b1c1 feat: add consecutive calendar week (WW) for naming series
The calendar week is based on ISO 8601 but behaves slightly different
for the first and last days of a year to ensure consecutiveness:

* If the first days of a year would be in week 53 then 00 is used
  instead.
* if the last days of a year would be in week 01 then 53 is used
  instead.

Closes #14413
2021-11-18 17:52:36 +01:00
Gavin D'souza
3446026555 chore: Update header: license.txt => LICENSE
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.
2021-09-03 12:02:59 +05:30
Gavin D'souza
c00a5003f4 refactor(tests): frappe.db.delete > frappe.db.sql
Use frappe.db.delete wherever possible. Get rid of all the frappe.db.sql
;)

This commit focuses on the frappe.tests module
2021-08-19 19:48:42 +05:30
leela
80d111baf2 refactor: set amended docname to original docname
Currently, whenever a document is amended it's name is set
to name-X(X is a counter) when amended again and so on. In this PR,
we have postfixed all cancelled document names with '-CAN' and new
cancelled documents gets a name as original_name-CANC-X.
so that amended docs can use the original name instead of name-X.
2021-08-09 14:59:07 +05:30
leela
b719e1481d Revert "refactor: set amended docname to original docname"
This reverts commit d459847ae3.
2021-07-28 17:00:12 +05:30
leela
d459847ae3 refactor: set amended docname to original docname
Currently, whenever a document is amended it's name is set
to name-X(X is a counter) when amended again and so on. In this PR,
we have changed all cancelled doc patterns to name-CAN-X,
so that amended docs can use the original name instead of name-X.
2021-07-21 10:51:32 +05:30
leela
f31d01a2a6 Revert "Merge pull request #13244 from prssanna/amended-doc-naming"
This reverts commit 58b95662c2, reversing
changes made to c553b7e23a.
2021-07-02 17:43:16 +05:30
Leela vadlamudi
4800ee8725
Merge branch 'develop' into amended-doc-naming 2021-07-02 10:47:47 +05:30
Gavin D'souza
e407b78506 chore: Drop dead and deprecated code
* Remove six for PY2 compatability since our dependencies are not, PY2
  is legacy.
* Removed usages of utils from future/past libraries since they are
  deprecated. This includes 'from __future__ ...' and 'from past...'
  statements.
* Removed compatibility imports for PY2, switched from six imports to
  standard library imports.
* Removed utils code blocks that handle operations depending on PY2/3
  versions.
* Removed 'from __future__ ...' lines from templates/code generators
* Used PY3 syntaxes in place of PY2 compatible blocks. eg: metaclass
2021-05-26 15:31:29 +05:30
Prssanna Desai
081677c6c4 fix: typo in test 2021-05-17 17:13:51 +05:30
prssanna
209ece8b6c fix: delete test submittable doctype 2021-05-17 17:13:51 +05:30