From d0988dc32c1034793530d843912a86fce331f4fa Mon Sep 17 00:00:00 2001 From: Bibin <17405044+bibinqcs@users.noreply.github.com> Date: Sun, 21 Jun 2026 17:25:19 +0000 Subject: [PATCH] fix(UAE VAT 201): bypass helper cache in tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit frappe.local is request-scoped, not test-scoped — it survives across unit-test methods. Two tests calling get_standard_rated_ expenses_total({"company": "_Test Company UAE VAT"}) hit the same cache key, so the second test (foreign-currency PI, expected 917.5) was seeing 250 carried over from the first. Short-circuit @_cached on frappe.flags.in_test so each test method queries fresh. Production callers run one execute() per request and have the cache cleared at the top of that call, so the optimisation still applies there. --- erpnext/regional/report/uae_vat_201/uae_vat_201.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/erpnext/regional/report/uae_vat_201/uae_vat_201.py b/erpnext/regional/report/uae_vat_201/uae_vat_201.py index e7979283f0f..1459602ac02 100644 --- a/erpnext/regional/report/uae_vat_201/uae_vat_201.py +++ b/erpnext/regional/report/uae_vat_201/uae_vat_201.py @@ -48,6 +48,14 @@ def _drill_down_link(text, filters, **extra): def _cached(fn): def wrapper(filters, *args, **kwargs): + # ``frappe.local`` survives across unit-test methods (it is request + # scoped, not test scoped). Two tests that call the same helper with + # equivalent filter dicts would otherwise share a cached value from + # the first test's data set. Bypass the cache in tests so each + # call hits the DB; production callers (one execute() per HTTP + # request, cache cleared at its start) still see the optimisation. + if frappe.flags.in_test: + return fn(filters, *args, **kwargs) cache = _get_cache() key = (fn.__name__, tuple(sorted((filters or {}).items()))) if key not in cache: