Skip to content

Commit 6581eb7

Browse files
committed
fix: improve version retrieval method and enhance error handling for CacheConfig
1 parent 74e17da commit 6581eb7

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,8 @@ jobs:
3030
- name: Check version change
3131
id: version-check
3232
run: |
33-
# Get current version from package
34-
CURRENT_VERSION=$(python -c "
35-
import sys
36-
sys.path.insert(0, 'src')
37-
import yokedcache
38-
print(yokedcache.__version__)
39-
")
33+
# Get current version from __init__.py without importing (safer)
34+
CURRENT_VERSION=$(grep '__version__ = ' src/yokedcache/__init__.py | sed 's/__version__ = "\(.*\)"/\1/')
4035
4136
echo "Current version: $CURRENT_VERSION"
4237

src/yokedcache/__init__.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,18 @@ def __init__(self, *args, **kwargs):
2323
)
2424

2525

26-
from .config import CacheConfig
26+
try:
27+
from .config import CacheConfig
28+
except ImportError:
29+
# If PyYAML is not available, create a placeholder that gives helpful error
30+
class CacheConfig: # type: ignore
31+
def __init__(self, *args, **kwargs):
32+
raise ImportError(
33+
"PyYAML is required for CacheConfig. Please install with: "
34+
"pip install pyyaml>=6.0"
35+
)
36+
37+
2738
from .decorators import cached, cached_dependency
2839
from .exceptions import (
2940
CacheConnectionError,

src/yokedcache/decorators.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -628,11 +628,19 @@ def sync_cached_method(*args, **kwargs):
628628
self._execute_cached_query(method, args, kwargs, method_name)
629629
)
630630
else:
631-
# Running loop exists, use asyncio.create_task
632-
# and wait for result
633-
return loop.run_until_complete(
634-
self._execute_cached_query(method, args, kwargs, method_name)
635-
)
631+
# Running loop exists, we can't use run_until_complete
632+
# Instead, we'll run in a new thread with its own event loop
633+
import concurrent.futures
634+
635+
# Run the coroutine in a new thread with its own event loop
636+
def _run_in_thread():
637+
return asyncio.run(
638+
self._execute_cached_query(method, args, kwargs, method_name)
639+
)
640+
641+
with concurrent.futures.ThreadPoolExecutor() as executor:
642+
future = executor.submit(_run_in_thread)
643+
return future.result()
636644

637645
# Return appropriate wrapper based on whether original method is async
638646
if inspect.iscoroutinefunction(method):
@@ -668,7 +676,8 @@ async def _execute_cached_query(
668676
result = method(*args, **kwargs)
669677

670678
# For read operations, cache the result
671-
if method_name in ("query", "get", "first", "all") and result is not None:
679+
read_ops = ("query", "get", "first", "all")
680+
if method_name in read_ops and result is not None:
672681
try:
673682
# Determine TTL and tags
674683
actual_ttl = self._ttl or self._cache.config.default_ttl

0 commit comments

Comments
 (0)