Merge pull request #15975 from resilient-tech/fix-limit-without-filter

fix: limit without filter
This commit is contained in:
mergify[bot] 2022-02-15 13:40:56 +00:00 committed by GitHub
commit 1df33cbfcf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View file

@ -153,6 +153,9 @@ class BaseDocument(object):
value = []
self.set(key, value)
if limit and isinstance(value, (list, tuple)) and len(value) > limit:
value = value[:limit]
return value
else:
return self.__dict__

View file

@ -264,7 +264,10 @@ class TestDocument(unittest.TestCase):
def test_limit_for_get(self):
doc = frappe.get_doc("DocType", "DocType")
# assuming DocType has more that 3 Data fields
# assuming DocType has more than 3 Data fields
self.assertEquals(len(doc.get("fields", limit=3)), 3)
# limit with filters
self.assertEquals(len(doc.get("fields", filters={"fieldtype": "Data"}, limit=3)), 3)
def test_virtual_fields(self):