File tree 3 files changed +39
-0
lines changed
3 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -91,6 +91,13 @@ def dynamic_type():
91
91
assoc_prop .value_attr ,
92
92
** field_kwargs ,
93
93
).get_type ()
94
+ else :
95
+ raise TypeError (
96
+ "Unsupported association proxy target type: {} for prop {} on type {}. "
97
+ "Please disable the conversion of this field using an ORMField." .format (
98
+ type (attr ), assoc_prop , obj_type
99
+ )
100
+ )
94
101
# else, not supported
95
102
96
103
return graphene .Dynamic (dynamic_type )
Original file line number Diff line number Diff line change @@ -68,6 +68,18 @@ def __repr__(self):
68
68
return "{} {}" .format (self .first_name , self .last_name )
69
69
70
70
71
+ class ProxiedReporter (Base ):
72
+ __tablename__ = "reporters_error"
73
+ id = Column (Integer (), primary_key = True )
74
+ first_name = Column (String (30 ), doc = "First name" )
75
+ last_name = Column (String (30 ), doc = "Last name" )
76
+ reporter_id = Column (Integer (), ForeignKey ("reporters.id" ))
77
+ reporter = relationship ("Reporter" , uselist = False )
78
+
79
+ # This is a hybrid property, we don't support proxies on hybrids yet
80
+ composite_prop = association_proxy ("reporter" , "composite_prop" )
81
+
82
+
71
83
class Reporter (Base ):
72
84
__tablename__ = "reporters"
73
85
Original file line number Diff line number Diff line change 29
29
Article ,
30
30
CompositeFullName ,
31
31
Pet ,
32
+ ProxiedReporter ,
32
33
Reporter ,
33
34
ShoppingCart ,
34
35
ShoppingCartItem ,
@@ -523,6 +524,25 @@ class Meta:
523
524
assert dynamic_field .get_type ().type .of_type == ArticleType
524
525
525
526
527
+ def test_should_throw_error_association_proxy_unsupported_target ():
528
+ class ProxiedReporterType (SQLAlchemyObjectType ):
529
+ class Meta :
530
+ model = ProxiedReporter
531
+
532
+ field = convert_sqlalchemy_association_proxy (
533
+ ProxiedReporter ,
534
+ ProxiedReporter .composite_prop ,
535
+ ProxiedReporterType ,
536
+ get_global_registry (),
537
+ default_connection_field_factory ,
538
+ True ,
539
+ mock_resolver ,
540
+ )
541
+
542
+ with pytest .raises (TypeError ):
543
+ field .get_type ()
544
+
545
+
526
546
def test_should_postgresql_uuid_convert ():
527
547
assert get_field (postgresql .UUID ()).type == graphene .UUID
528
548
You can’t perform that action at this time.
0 commit comments