File tree Expand file tree Collapse file tree 2 files changed +39
-2
lines changed
Expand file tree Collapse file tree 2 files changed +39
-2
lines changed Original file line number Diff line number Diff line change @@ -749,7 +749,7 @@ async def execute(self, exhaust_results=True):
749749
750750 async def first (self ):
751751 query = self .copy (offset = 0 , limit = 1 , sort_fields = self .sort_fields )
752- results = await query .execute ()
752+ results = await query .execute (exhaust_results = False )
753753 if not results :
754754 raise NotFoundError ()
755755 return results [0 ]
Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ class Member(BaseHashModel):
4646 last_name : str = Field (index = True )
4747 email : str = Field (index = True )
4848 join_date : datetime .date
49- age : int = Field (index = True )
49+ age : int = Field (index = True , sortable = True )
5050 bio : str = Field (index = True , full_text_search = True )
5151
5252 class Meta :
@@ -357,6 +357,43 @@ def test_validation_passes(m):
357357 )
358358 assert member .first_name == "Andrew"
359359
360+ @pytest .mark .asyncio
361+ async def test_retrieve_first (m ):
362+ member = m .Member (
363+ first_name = "Simon" ,
364+ last_name = "Prickett" ,
365+ email = "s@example.com" ,
366+ join_date = today ,
367+ age = 99 ,
368+ bio = "This is the bio field for this user." ,
369+ )
370+
371+ await member .save ()
372+
373+ member2 = m .Member (
374+ first_name = "Another" ,
375+ last_name = "Member" ,
376+ email = "m@example.com" ,
377+ join_date = today ,
378+ age = 98 ,
379+ bio = "This is the bio field for this user." ,
380+ )
381+
382+ await member2 .save ()
383+
384+ member3 = m .Member (
385+ first_name = "Third" ,
386+ last_name = "Member" ,
387+ email = "t@example.com" ,
388+ join_date = today ,
389+ age = 97 ,
390+ bio = "This is the bio field for this user." ,
391+ )
392+
393+ await member3 .save ()
394+
395+ first_one = await m .Member .find ().sort_by ("age" ).first ()
396+ assert first_one == member3
360397
361398@pytest .mark .asyncio
362399async def test_saves_model_and_creates_pk (m ):
You can’t perform that action at this time.
0 commit comments