Commit graph

256 commits

Author SHA1 Message Date
Akhil Narang
84ef6ec677
refactor: fixup with ruff 0.8.1
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2024-12-04 13:18:04 +05:30
David Arnold
3c1392c8fd
fix: meta signature (#28526)
* fix: meta

* fix: test case

save is required:

1. Fetch values
```python
	def get_invalid_links(self, is_submittable=False):
		"""Return list of invalid links and also update fetch values if not set."""
		...
```

2. Is triggered by
```python

	def _validate_links(self):
		if self.flags.ignore_links or self._action == "cancel":
			return
        ...
```

3. Which is triggered by either `_save` or `insert`

----

`reload` does not trigger link fetch
```python
	def reload(self) -> "Self":
		"""Reload document from database"""
		return self.load_from_db()
```

Neither does the new calling path which does not excempt Document
from caching when initializing meta.

It can be proven that this revert would be an alternative fix. But this
seems design by accident and there's no preceivable reason to excempt
Document args from being cached normally.

diff --git a/frappe/model/meta.py b/frappe/model/meta.py
index c4321f0128..87452c812c 100644
--- a/frappe/model/meta.py
+++ b/frappe/model/meta.py
@@ -70,11 +70,10 @@ def get_meta(doctype: str | dict | DocRef, cached=True) -> "_Meta":
 	Returns:
 	    Meta object for the given doctype.
 	"""
-	if cached and (
-		doctype_name := getattr(doctype, "doctype", doctype)
-		if not isinstance(doctype, dict)
-		else doctype.get("doctype")
-	):
+	if cached and not isinstance(doctype, Document):
+		doctype_name = (
+			getattr(doctype, "doctype", doctype) if not isinstance(doctype, dict) else doctype.get("doctype")
+		)
 		if meta := frappe.cache.hget("doctype_meta", doctype_name):
 			return meta

Therefore, we comply the test.
2024-11-20 04:17:38 +00:00
David Arnold
15d122025f
feat: get_meta can derive meta from dict (#28525) 2024-11-20 01:36:04 +00:00
David Arnold
d5fd8d7c20
chore(docref): fix circular imports (#28282) 2024-10-24 22:31:12 +02:00
David Arnold
7348572af8
feat: docref identifier / proxy (#27973)
* feat: add DocRef

* feat: Add comprehensive test cases for DocRef functionality

* chore(db): add field type hints

* fix: ensure document stringer fulfills the DocRef contract
2024-10-19 09:40:26 +05:30
David Arnold
5d3697500e
refactor: improve maintainability with a simple dispatcher (#27975)
* refactor: improve maintainability with a simple dispatcher

* refactor: improve maintainability with a init dispatcher on Document

* refactor: improve maintainability with an init dispatcher on meta
2024-10-06 16:56:40 +00:00
David
d05f70f9ba
fix: return correct types for owner and modified_by 2024-10-03 23:25:11 +02:00
David
2de43f7797
feat: improve placement for custom field sections and columns 2024-09-26 12:54:30 +02:00
Raffael Meyer
b91cacdd18
feat!: enhance Language to become more of a Locale (#27178) 2024-09-21 16:02:58 +02:00
marination
a893341f95 fix: get_valid_fields excludes show_on_timeline, breaking migrations
Co-authored-by: Gavin <gavin.dsouza@switchup.de>
2024-09-02 17:27:50 +02:00
Gavin D'souza
074da5c553
fix: Separate meta.get_valid_fields from *columns 2024-08-28 18:12:42 +02:00
Gavin D'souza
151de897f1
fix: Use doc.get to safely check for attr
This bypasses the bungle during site creations when meta isn't present in
the database yet
2024-08-28 11:59:25 +02:00
Gavin D'souza
12e3cee4a6
fix!: Skip virtual fields in meta.get_valid_columns 2024-08-28 11:42:43 +02:00
Akhil Narang
3f1e19de85
refactor(treewide): enable RUF rules
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2024-02-21 16:20:28 +05:30
Akhil Narang
26ae0f3460
fix: ruff fixes
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2024-02-07 17:04:31 +05:30
Ankush Menat
de9ac89748 style: re-format with ruff 2024-02-05 18:53:33 +05:30
Corentin Flr
f8ff2308e2
Merge branch 'frappe:develop' into fix-fieldlevel-access-to-shared-document-list 2024-01-15 01:32:51 +01:00
Ankush Menat
1f6201b4af feat: lazy global translated strings 2024-01-10 21:28:01 +05:30
Ankush Menat
d09df92497 fix(DX): Type annotations for Meta
`frappe.get_meta` returns which is 90% `DocType` + 10% `Meta` specific
stuff, this hack just allows us to mix both for autocompletions.
2024-01-10 15:58:03 +05:30
Corentin Flr
d7026b8a26
fix(meta)!: Allow level 0 fields when a doc has been shared with user 2023-12-21 14:40:44 +01:00
Ankush Menat
0fd6f5eed7
Merge pull request #23827 from frappe/api-docs
docs: add Python API missing docstrings / type hints
2023-12-21 12:13:05 +05:30
Ankush Menat
5ecacd0cd7
Merge pull request #23865 from ankush/no_virtual_select_star
fix: skip virtual fields in perm level checks during DB Query
2023-12-20 12:15:48 +05:30
Ankush Menat
5deabdde21 fix: skip virtual fields in perm level checks during DB Query
DB Query can't access virtual fields so it should ignore all virtual
fields.
2023-12-20 12:00:08 +05:30
Hussain Nagaria
8d2137c265 docs: consistent doc strings 2023-12-18 18:27:39 +05:30
marination
d4129721ce fix: Treat Document Links entries as all non-std fields
- Since the field name is specified use it as a non standard field because it is hard to determine which field is standard. It is often wrong to assume the first entry has the statndard field
2023-11-24 16:39:50 +01:00
Deepesh Garg
b3742b45a8
Merge pull request #22104 from GursheenK/doc-comparator
feat: audit trail
2023-09-13 14:04:15 +05:30
Gursheen Anand
177955a12f fix: check label for fields 2023-09-11 11:06:01 +05:30
Gursheen Anand
0d80ffc988 fix: return df label only when not none 2023-08-18 11:01:55 +05:30
Ankush Menat
c7847395da
fix: remove thread-unsafe class attributes (#22097)
The problem is same as mutable defaults. Container type class attributes
are mutable and shared between all objects.

```python
class CLS:
    attr = {}
    ...

a = CLS()
b = CLS()

a.attr is b.attr  # => True
```
2023-08-17 20:11:20 +05:30
barredterra
88c8baa9ee refactor: for append to extend, merge list extend
Replace a for append loop with list extend.
Create the list with values instead of creating
an empty list and extending it with another list.
2023-08-09 13:25:39 +02:00
Ankush Menat
8a30667a97
fix: Fetch non-cached version of Meta on Customize Form. (#21269)
* fix: Replace meta cache when uncached meta is requested

* fix: use meta from DB on customize form

* refactor: make cached kw only, use _dev_server
2023-06-12 14:59:42 +05:30
Devin Slauenwhite
19d211f1d2
feat: rearranging standard fields in customize form (#19822)
* feat: rearranging standing fields

* fix: fixed creation of property setter

* refactor: renamed setup_sortable

* fix: loading field_order property

* refactor: removed redundant db call

* fix: field_order not found

* test: Added tests for field order in customize form

* refactor: better naming

* refactor: simplified logic

* feat: Updating field order on custom field creation

* feat: Added support for custom fiels

* refactor: moving to meta

* refactor: changed property type to json

* fix: new standard field insert order.

* fix: don't modify insert_after of system generated custom fields.

# This is because system generated fields are to be treated as standard fields. If the user restores the form to default, this value will be used to reset the original position.

# The new position of form fields are stored in the field_order Property Setter.

* fix: treat system generated fields as standard fields when sorting.

* revert: check for is_system_generated

* Revert "fix: new standard field insert order."

This reverts commit 6cdbe42f28d5944165dd100a9bb9172463951fda.

* fix: prioritize field_order over insert_after.

# Use insert_after as fallback in event the field doesn't exist in field_order

* fix(test): delete existing custom field

* fix: order of standard fields without field_order property.

* Revert "Revert "fix: new standard field insert order.""

This reverts commit c830f1ba2fe1e602b09c11a897869d9992097c1e.

* test: field order of newly migrated standard fields.

* fix(test): clear test_standard_field from previous test run.

* fix: sort with insert_after for system generated fields.

* fix(test): reset standard field creation before re-run and after successful test.

* fix: insert_after position should be + 1

* chore: remove debug statement

* test: system generated customized fields

* chore: remove print

* chore: lint all

* fix: show quick link to Table MultiSelect DocTypes

* refactor: change backend implementation of `CustomizeForm` and `Meta`

* test: simplify tests

* fix: rename `idx` to `index` for clarity

* perf: define `existing_fields` conditionally

---------

Co-authored-by: Aradhya <aradhyatripathi51@gmail.com>
Co-authored-by: Aradhya Tripathi <67282231+Aradhya-Tripathi@users.noreply.github.com>
Co-authored-by: Sagar Vora <sagar@resilient.tech>
2023-06-08 17:14:44 +05:30
Ankush Menat
fa6dc03cc8
refactor: frappe.cache() usage to frappe.cache (#21282) 2023-06-08 11:47:17 +05:30
Gavin D'souza
a1f59c5a82 fix: Allow only search fields for select permission type 2023-04-22 12:46:15 +05:30
Gavin D'souza
36ee97a8f8 fix: Dont assume user & permission_type in get_permitted_fileds 2023-04-21 17:40:00 +05:30
Ankush Menat
163b9290e3
Merge pull request #19916 from gavindsouza/distinct-get_count
fix(db_query): apply_fieldlevel_read_permissions
2023-02-14 11:56:22 +05:30
Gavin D'souza
ebc32a34f6 fix(trim-tables): Exclude virtual doctypes from query 2023-02-09 15:29:06 +05:30
Gavin D'souza
db209cbdf7 fix: Permit no fields if dt is table and no parenttype is specified 2023-02-06 13:33:49 +05:30
Gavin D'souza
18395b66f0 fix(get_permitted_fieldnames): Return all fields if permissions not defined 2023-02-06 12:42:06 +05:30
Gavin D'souza
f9eff18fd0 fix(meta): Remove faulty permitted fields cache
The Meta property didn't respect user parameter passed
2023-02-03 22:12:26 +05:30
Gavin D'souza
4accf0ed9d fix: Consider virtual fields in fields with values conditionally 2023-01-25 12:38:15 +05:30
Gavin D'souza
5c5bd2b104 refactor: Meta.get_permitted_fieldnames
* Remove older API that returned list[df]
* Rename fields in usage scope & Meta internals
2023-01-24 13:09:43 +05:30
Gavin D'souza
d71522091e fix: Apply permlevel restrictions to DatabaseQuery
Allow reading only accessible fields for given user session if
ignore_permissions (get_all) is unset.
2023-01-09 15:47:21 +05:30
Sagar Vora
d072e20cbd chore: fix typo 2022-12-23 06:13:07 +00:00
Sagar Vora
7fdcafddce chore: remove code for handling old dict cache 2022-12-23 06:13:07 +00:00
Sagar Vora
2fd2d426cc
fix: better check of whether doctype is child table (#19329)
* fix: better check of whether doctype is child table

* perf: init `_table_fields` earlier
2022-12-19 11:50:16 +05:30
Raffael Meyer
04d1292cf1
fix: consistent translation in meta.get_label (#19080) 2022-12-02 23:38:15 +05:30
Ankush Menat
a6af1ed542 feat: bulk insert simple Document objects 2022-11-28 15:32:20 +05:30
Sagar Vora
cb7d25a293
fix(meta): ensure that insert_after is always considered when sorting fields (#18682)
* fix(meta): ensure that `insert_after` is always considered when sorting fields

* test: add nosemgrep to comment

Co-authored-by: Dany Roberts <danyrt@wahni.com>
2022-10-31 15:37:55 +05:30
Ankush Menat
2b6fc68088
Revert "fix: drop Meta cache during update" (#18186)
* Revert "fix: drop Meta cache during update (#18182)"

This reverts commit 656f6df257.

* fix: replace meta cache keys

Old keys stored different types of data `dict` changing key to indicate
change in type.
2022-09-19 21:28:45 +05:30