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

NAS-133055 / 25.04 / fix the "in" operator in the filters to pool.dataset.query #15209

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/middlewared/middlewared/plugins/pool_/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ def query(self, filters, options):
# Optimization for cases in which they can be filtered at zfs.dataset.query
zfsfilters = []
filters = filters or []
if len(filters) == 1 and len(filters[0]) == 3 and list(filters[0][:2]) == ['id', '=']:
zfsfilters.append(copy.deepcopy(filters[0]))
if len(filters) == 1 and len(f := filters[0]) == 3 and f[0] in ('id', 'name') and f[1] in ('=', 'in'):
zfsfilters.append(copy.deepcopy(f))

internal_datasets_filters = self.middleware.call_sync('pool.dataset.internal_datasets_filters')
filters.extend(internal_datasets_filters)
Expand Down
21 changes: 21 additions & 0 deletions tests/api2/test_pool_dataset_create.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from itertools import product

import pytest

from middlewared.test.integration.assets.pool import dataset
Expand All @@ -10,3 +12,22 @@ def test_pool_dataset_create_ancestors(child):
name = f"{test_ds}/{child}"
call("pool.dataset.create", {"name": name, "create_ancestors": True})
call("pool.dataset.get_instance", name)


def test_pool_dataset_query():
fields = ("id", "name")
ops = ("=", "in")
flats = (True, False)

with dataset("query_test") as ds:
# Try all combinations
results = (call(
"pool.dataset.query",
[[field, op, ds if op == "=" else [ds]]],
{"extra": {"flat": flat, "properties": []}}
) for field, op, flat in product(fields, ops, flats))

# Check all the returns are the same
first = next(results)
for next_ds in results:
assert next_ds == first
Loading