mirror of
				https://github.com/graphql-python/graphene-django.git
				synced 2025-11-04 09:57:53 +03:00 
			
		
		
		
	Do not access the internals of SimpleLazyObject (#945)
				
					
				
			This commit is contained in:
		
							parent
							
								
									ed4937f9df
								
							
						
					
					
						commit
						2225ed62e1
					
				| 
						 | 
					@ -60,6 +60,31 @@ def test_should_query_simplelazy_objects():
 | 
				
			||||||
    assert result.data == {"reporter": {"id": "1"}}
 | 
					    assert result.data == {"reporter": {"id": "1"}}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def test_should_query_wrapped_simplelazy_objects():
 | 
				
			||||||
 | 
					    class ReporterType(DjangoObjectType):
 | 
				
			||||||
 | 
					        class Meta:
 | 
				
			||||||
 | 
					            model = Reporter
 | 
				
			||||||
 | 
					            fields = ("id",)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    class Query(graphene.ObjectType):
 | 
				
			||||||
 | 
					        reporter = graphene.Field(ReporterType)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        def resolve_reporter(self, info):
 | 
				
			||||||
 | 
					            return SimpleLazyObject(lambda: SimpleLazyObject(lambda: Reporter(id=1)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    schema = graphene.Schema(query=Query)
 | 
				
			||||||
 | 
					    query = """
 | 
				
			||||||
 | 
					        query {
 | 
				
			||||||
 | 
					          reporter {
 | 
				
			||||||
 | 
					            id
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    result = schema.execute(query)
 | 
				
			||||||
 | 
					    assert not result.errors
 | 
				
			||||||
 | 
					    assert result.data == {"reporter": {"id": "1"}}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_should_query_well():
 | 
					def test_should_query_well():
 | 
				
			||||||
    class ReporterType(DjangoObjectType):
 | 
					    class ReporterType(DjangoObjectType):
 | 
				
			||||||
        class Meta:
 | 
					        class Meta:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -272,12 +272,9 @@ class DjangoObjectType(ObjectType):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @classmethod
 | 
					    @classmethod
 | 
				
			||||||
    def is_type_of(cls, root, info):
 | 
					    def is_type_of(cls, root, info):
 | 
				
			||||||
        if isinstance(root, SimpleLazyObject):
 | 
					 | 
				
			||||||
            root._setup()
 | 
					 | 
				
			||||||
            root = root._wrapped
 | 
					 | 
				
			||||||
        if isinstance(root, cls):
 | 
					        if isinstance(root, cls):
 | 
				
			||||||
            return True
 | 
					            return True
 | 
				
			||||||
        if not is_valid_django_model(type(root)):
 | 
					        if not is_valid_django_model(root.__class__):
 | 
				
			||||||
            raise Exception(('Received incompatible instance "{}".').format(root))
 | 
					            raise Exception(('Received incompatible instance "{}".').format(root))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if cls._meta.model._meta.proxy:
 | 
					        if cls._meta.model._meta.proxy:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user