Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement is set operator #25180

Closed
rareMaxim opened this issue Feb 29, 2024 · 2 comments · Fixed by #25182
Closed

Implement is set operator #25180

rareMaxim opened this issue Feb 29, 2024 · 2 comments · Fixed by #25182

Comments

@rareMaxim
Copy link
Contributor

Description of the issue

In Virtual DocType filters "is set" and "is not set" not working.

Context information (for bug reports)

for example i see https://github.com/frappe/frappe/blob/develop/frappe/core/doctype/recorder/recorder.py#L67

this method call evaluate_filters(req, filters)]. Open this method:

if not compare(doc.get(f.fieldname), f.operator, f.value, f.fieldtype):
and we see its use operator_map dictionary
operator_map = {
. In this dictionary not operators "is set" and "is not set"

Output of bench version

(paste here)

Steps to reproduce the issue

  1. Create Virtual DocType
  2. Try use filter Is Set and Is Not Set

Observed result

Expected result

Stacktrace / full error message

(paste here)

Additional information

OS version / distribution, Frappe install method, etc.

@rareMaxim rareMaxim added the bug label Feb 29, 2024
@ankush ankush added feature-request and removed bug labels Mar 1, 2024
@ankush ankush changed the title Virtual DocType filter bug Implement is set operator Mar 1, 2024
@ankush
Copy link
Member

ankush commented Mar 1, 2024

If someone wants to take a stab at this:

  • is set means some value is set. For nullable fields this means value is None or falsy like empty string. For numeric fields this doesn't make sense. is not set is just opposite of it.

@rareMaxim
Copy link
Contributor Author

rareMaxim commented Mar 1, 2024

Anybody, pls add in

operator_map = {

line:

"is": lambda a, b: (a and (b == 'set')) or (not a and (b == 'not set')),

total:

operator_map = {
	# startswith
	"^": lambda a, b: (a or "").startswith(b),
	# in or not in a list
	"in": lambda a, b: operator.contains(b, a),
	"not in": lambda a, b: not operator.contains(b, a),
	# comparison operators
	"=": operator.eq,
	"!=": operator.ne,
	">": operator.gt,
	"<": operator.lt,
	">=": operator.ge,
	"<=": operator.le,
	"not None": lambda a, b: a is not None,
	"None": lambda a, b: a is None,
	"like": sql_like,
	"not like": lambda a, b: not sql_like(a, b),
	"is": lambda a, b: (a and (b == 'set')) or (not a and (b == 'not set')),
}

rareMaxim added a commit to rareMaxim/frappe that referenced this issue Mar 1, 2024
ankush added a commit that referenced this issue Mar 2, 2024
* Implementation is set operator. fix issue #25180

* Refactored filtrer operator `is`,
Add tests

* fix: Correct implementation for `is set`

---------

Co-authored-by: Ankush Menat <ankush@frappe.io>
mergify bot pushed a commit that referenced this issue Mar 2, 2024
* Implementation is set operator. fix issue #25180

* Refactored filtrer operator `is`,
Add tests

* fix: Correct implementation for `is set`

---------

Co-authored-by: Ankush Menat <ankush@frappe.io>
(cherry picked from commit eff50e1)

# Conflicts:
#	frappe/tests/test_utils.py
ankush pushed a commit that referenced this issue Mar 2, 2024
* Implementation is set operator. fix issue #25180

* Refactored filtrer operator `is`,
Add tests

* fix: Correct implementation for `is set`

---------

Co-authored-by: Ankush Menat <ankush@frappe.io>
(cherry picked from commit eff50e1)

# Conflicts:
#	frappe/tests/test_utils.py

Co-authored-by: Maxim Sysoev <maks4a@gmail.com>
frappe-pr-bot pushed a commit that referenced this issue Mar 5, 2024
# [15.17.0](v15.16.1...v15.17.0) (2024-03-05)

### Bug Fixes

* add "If Owner" column to roles viewer ([#25218](#25218)) ([#25220](#25220)) ([adf6a2a](adf6a2a))
* always show is_standard on web form ([#25144](#25144)) ([#25148](#25148)) ([196483b](196483b))
* better error message ([b94e978](b94e978))
* dont translate numbers ([#25208](#25208)) ([#25210](#25210)) ([c659eca](c659eca))
* escalate print failures ([a987c2d](a987c2d))
* escape single quotes ([#25104](#25104)) ([#25154](#25154)) ([adb7e38](adb7e38)), closes [/github.com//pull/25078#discussion_r1504084483](https://github.com//github.com/frappe/frappe/pull/25078/issues/discussion_r1504084483)
* Export `None` as type if select as no options ([#25211](#25211)) ([#25212](#25212)) ([79a8afd](79a8afd))
* filter Implementation is set operator ([#25182](#25182)) ([#25195](#25195)) ([20a7879](20a7879)), closes [#25180](#25180)
* No need to sort keys while saving JSON to DB ([#25205](#25205)) ([#25206](#25206)) ([a471499](a471499))
* Only validate fetch from when user modifies it ([72da497](72da497))
* race condition on deletes (backport [#25170](#25170)) ([#25171](#25171)) ([1657d55](1657d55))
* **search:** Don't break when query doesn't return title ([#25168](#25168)) ([#25197](#25197)) ([3dafbf9](3dafbf9))
* **setup_module_map:** fix caching ([338c895](338c895))
* specify print_language in communication attachments ([4e53b12](4e53b12))
* task_id parameter for publish_progress ([30a2f27](30a2f27))
* update file attached_to details in submitted doc ([#25141](#25141)) ([73f1a73](73f1a73))
* Use current language in attachment prints ([ea4c11b](ea4c11b))
* use name for RQ worker instead of PID ([#25175](#25175)) ([#25177](#25177)) ([7264734](7264734))
* **UX:** correctly disable standard web form form ([#25143](#25143)) ([2d907e7](2d907e7))
* **UX:** list filter take zero as null ([#25156](#25156)) ([#25222](#25222)) ([963ff89](963ff89))
* **UX:** reload form after renaming field ([#25159](#25159)) ([#25161](#25161)) ([7754e4a](7754e4a))
* **UX:** set default print language from print format ([c11f140](c11f140))

### Features

* Add doc rename hook in server script ([#25085](#25085)) ([#25110](#25110)) ([b729c03](b729c03))
* let users unlock stuck documents (backport [#24782](#24782)) ([#25225](#25225)) ([b0db641](b0db641))
* task_id for submit_cancel_or_update_docs ([bf8d102](bf8d102))
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants