Skip to content

Commit 449c4d2

Browse files
committed
Merge dev into main
2 parents 4abfb68 + 82226b0 commit 449c4d2

File tree

7 files changed

+48
-43
lines changed

7 files changed

+48
-43
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# OSBot-Utils
22

3-
![Current Release](https://img.shields.io/badge/release-v3.49.0-blue)
3+
![Current Release](https://img.shields.io/badge/release-v3.49.1-blue)
44
![Python](https://img.shields.io/badge/python-3.8+-green)
55
![Type-Safe](https://img.shields.io/badge/Type--Safe-✓-brightgreen)
66
![Caching](https://img.shields.io/badge/Caching-Built--In-orange)

osbot_utils/helpers/cache_on_self/Cache_On_Self.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ def handle_call(self, args: tuple, kwargs: dict) -> Any:
3737
return self.execute(args, kwargs)
3838

3939
if not kwargs and len(args) == 1: # Fast path for common case: no kwargs, single arg (self)
40-
target_self = args[0]
41-
cache_key = self.no_args_key
42-
43-
if self.cache_storage.has_cached_value(target_self, cache_key): # Use cache_storage
40+
target_self = args[0]
41+
cache_key = self.no_args_key
42+
if self.reload_next:
43+
self.reload_next = False
44+
elif self.cache_storage.has_cached_value(target_self, cache_key): # Use cache_storage
4445
self.metrics.hits += 1 # Increment cache Hit
4546
return self.cache_storage.get_cached_value(target_self, cache_key) # Use cache_storage
4647

osbot_utils/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v3.49.0
1+
v3.49.1

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "osbot_utils"
3-
version = "v3.49.0"
3+
version = "v3.49.1"
44
description = "OWASP Security Bot - Utils"
55
authors = ["Dinis Cruz <[email protected]>"]
66
license = "MIT"

tests/unit/helpers/cache_on_self/test_Cache_Controller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from unittest import TestCase
1+
from unittest import TestCase
22
from osbot_utils.helpers.cache_on_self.Cache_Controller import Cache_Controller
33
from osbot_utils.testing.Catch import Catch
44

tests/unit/helpers/cache_on_self/test__bugs__cache_on_self.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,38 +29,4 @@ def method(self, value):
2929
gc.collect()
3030
assert len(cache_manager.cache_storage.cache_data) == 1 # BUG: reference is still there
3131

32-
def test__bug__reload_next_flag_isolation_between_instances(self):
33-
"""Test that reload_next flag is properly isolated between instances"""
34-
class Reload_Flag_Class:
35-
def __init__(self, name):
36-
self.name = name
37-
self.call_count = 0
38-
39-
@cache_on_self
40-
def method(self):
41-
self.call_count += 1
42-
return f"{self.name} call {self.call_count}"
43-
44-
obj1 = Reload_Flag_Class("obj1")
45-
obj2 = Reload_Flag_Class("obj2")
46-
47-
# Initial calls
48-
assert obj1.method() == "obj1 call 1"
49-
assert obj2.method() == "obj2 call 1"
50-
51-
# Set reload_next on obj1's cache manager
52-
cache1 = obj1.method(__return__='cache_on_self')
53-
cache2 = obj2.method(__return__='cache_on_self')
54-
55-
cache1.reload_next = True
56-
57-
# Verify isolation - obj2 uses cache, obj1 reloads
58-
assert obj2.method() == "obj2 call 1" # Cache hit - correct!
59-
assert obj1.method() != "obj1 call 2" # Reload triggered # BUG should be equal
60-
assert obj1.method() == "obj1 call 1" # Reload triggered
61-
62-
63-
# Verify flags
64-
assert cache1.reload_next is True # Reset after use # BUG should be False
65-
assert cache2.reload_next is False # Reset after use
6632

tests/unit/helpers/cache_on_self/test__regression__cache_on_self.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,4 +543,42 @@ def get_sensitive_data(self, resource_id):
543543
# 2. Access the shared cache storage that contains admin's cached data
544544
for instance, cache_dict in cache_mgr.cache_storage.cache_data.items():
545545
assert instance.user_token == 'user_token'
546-
assert list(cache_dict.values()) == ['Access denied for secret_file']
546+
assert list(cache_dict.values()) == ['Access denied for secret_file']
547+
548+
549+
def test__regression__reload_next_flag_isolation_between_instances(self): # Test that reload_next flag is properly isolated between instances
550+
class Reload_Flag_Class:
551+
def __init__(self, name):
552+
self.name = name
553+
self.call_count = 0
554+
555+
@cache_on_self
556+
def method(self):
557+
self.call_count += 1
558+
return f"{self.name} call {self.call_count}"
559+
560+
obj1 = Reload_Flag_Class("obj1")
561+
obj2 = Reload_Flag_Class("obj2")
562+
563+
# Initial calls
564+
assert obj1.method() == "obj1 call 1"
565+
assert obj2.method() == "obj2 call 1"
566+
567+
# Set reload_next on obj1's cache manager
568+
cache1 = obj1.method(__return__='cache_on_self')
569+
cache2 = obj2.method(__return__='cache_on_self')
570+
571+
cache1.reload_next = True
572+
573+
# Verify isolation - obj2 uses cache, obj1 reloads
574+
assert obj2.method() == "obj2 call 1" # Cache hit - correct!
575+
#assert obj1.method() != "obj1 call 2" # Reload triggered # BUG should be "obj1 call 2"
576+
assert obj1.method() == "obj1 call 2" # Reload triggered # FIXED
577+
#assert obj1.method() == "obj1 call 1" # Reload triggered # BUG should be "obj1 call 2"
578+
assert obj1.method() == "obj1 call 2" # Reload triggered # FIXED
579+
580+
581+
# Verify flags
582+
#assert cache1.reload_next is True # Reset after use # BUG should be False
583+
assert cache1.reload_next is False # Reset after use # FIXED
584+
assert cache2.reload_next is False # Reset after use

0 commit comments

Comments
 (0)