Skip to content

Commit 2660ad4

Browse files
committed
RDBC-1025: lazily.load(None) now returns Lazy(None) instead of None
`if not ids: return None` returned the bare None value for a None id, so lazy.value raised AttributeError. Now returns Lazy(lambda: None), so lazy.value is None as C# specifies. Regression test: test_lazy_load_null.py verifies that lazily.load(None) resolves to None without raising AttributeError.
1 parent 024ec70 commit 2660ad4

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

ravendb/documents/session/operations/lazy.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ def include(self, path: str) -> LazyMultiLoaderWithInclude:
191191
def load(
192192
self, ids: Union[List[str], str], object_type: Optional[Type[_T]] = None, on_eval: Callable = None
193193
) -> Optional[Lazy[Union[Dict[str, object], object]]]:
194+
if ids is None:
195+
return Lazy(lambda: None)
194196
if not ids:
195197
return None
196198

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""
2+
Lazy load: lazily.load(None) returns a Lazy that resolves to None.
3+
4+
C# reference: SlowTests/Issues/RavenDB_21859.cs
5+
Load_And_Lazy_Load_Should_Return_Null_When_Id_Is_Null
6+
"""
7+
8+
from ravendb.tests.test_base import TestBase
9+
10+
11+
class User:
12+
def __init__(self, name: str = None):
13+
self.name = name
14+
15+
16+
class TestRavenDB21859(TestBase):
17+
def setUp(self):
18+
super().setUp()
19+
20+
def test_load_null_id_returns_none(self):
21+
with self.store.open_session() as session:
22+
result = session.load(None, User)
23+
self.assertIsNone(result)
24+
25+
def test_lazily_load_null_id_returns_none(self):
26+
with self.store.open_session() as session:
27+
lazy = session.advanced.lazily.load(None, User)
28+
session.advanced.eagerly.execute_all_pending_lazy_operations()
29+
self.assertIsNone(lazy.value)

0 commit comments

Comments
 (0)