File tree Expand file tree Collapse file tree 1 file changed +56
-0
lines changed Expand file tree Collapse file tree 1 file changed +56
-0
lines changed Original file line number Diff line number Diff line change @@ -681,3 +681,59 @@ class Address(m.BaseHashModel):
681
681
Address .redisearch_schema ()
682
682
== f"ON HASH PREFIX 1 { key_prefix } SCHEMA pk TAG SEPARATOR | a_string TAG SEPARATOR | a_full_text_string TAG SEPARATOR | a_full_text_string AS a_full_text_string_fts TEXT an_integer NUMERIC SORTABLE a_float NUMERIC"
683
683
)
684
+
685
+
686
+ @py_test_mark_asyncio
687
+ async def test_primary_key_model_error (m ):
688
+
689
+ class Customer (m .BaseHashModel ):
690
+ id : int = Field (primary_key = True , index = True )
691
+ first_name : str = Field (primary_key = True , index = True )
692
+ last_name : str
693
+ bio : Optional [str ]
694
+
695
+ await Migrator ().run ()
696
+
697
+ with pytest .raises (RedisModelError , match = "You must define only one primary key for a model" ):
698
+ _ = Customer (
699
+ id = 0 ,
700
+ first_name = "Mahmoud" ,
701
+ last_name = "Harmouch" ,
702
+ bio = "Python developer, wanna work at Redis, Inc."
703
+ )
704
+
705
+
706
+ @py_test_mark_asyncio
707
+ async def test_primary_pk_exists (m ):
708
+
709
+ class Customer1 (m .BaseHashModel ):
710
+ id : int
711
+ first_name : str
712
+ last_name : str
713
+ bio : Optional [str ]
714
+
715
+ class Customer2 (m .BaseHashModel ):
716
+ id : int = Field (primary_key = True , index = True )
717
+ first_name : str
718
+ last_name : str
719
+ bio : Optional [str ]
720
+
721
+ await Migrator ().run ()
722
+
723
+ customer = Customer1 (
724
+ id = 0 ,
725
+ first_name = "Mahmoud" ,
726
+ last_name = "Harmouch" ,
727
+ bio = "Python developer, wanna work at Redis, Inc."
728
+ )
729
+
730
+ assert 'pk' in customer .__fields__
731
+
732
+ customer = Customer2 (
733
+ id = 1 ,
734
+ first_name = "Kim" ,
735
+ last_name = "Brookins" ,
736
+ bio = "This is member 2 who can be quite anxious until you get to know them." ,
737
+ )
738
+
739
+ assert 'pk' not in customer .__fields__
You can’t perform that action at this time.
0 commit comments