arskom / spyne

A transport agnostic sync/async RPC library that focuses on exposing services with a well-defined API using popular protocols.
http://spyne.io
Other
1.13k stars 312 forks source link

AttributeError with django 1.11.5 models #542

Open hadeelsharaf opened 7 years ago

hadeelsharaf commented 7 years ago

I had this error while creating a service to a django project : AttributeError: 'Options' object has no attribute get_all_field_names this is the code:

User = get_user_model()

class Container(DjangoComplexModel):
    class Attributes(DjangoComplexModel.Attributes):
        django_model = User
        django_exclude = [] 

this part of the tracback:

  from .services import hello_world_service, app, HelloWorldService
  File "/home/hadeel/projects/sadie_service/service/services.py", line 50, in <module>
    class Container(DjangoComplexModel):
  File "/home/hadeel/.virtualenvs/sadie/lib/python3.5/site-packages/spyne/util/meta.py", line 66, in preparing_constructor
    return constructor(cls, name, bases, attributes)
  File "/home/hadeel/.virtualenvs/sadie/lib/python3.5/site-packages/spyne/util/django.py", line 427, in __new__
    optional_relations=optional_relations)
  File "/home/hadeel/.virtualenvs/sadie/lib/python3.5/site-packages/spyne/util/django.py", line 291, in map
    for field in self._get_fields(django_model, exclude):
  File "/home/hadeel/.virtualenvs/sadie/lib/python3.5/site-packages/spyne/util/django.py", line 268, in _get_fields
    meta.get_all_field_names())
AttributeError: 'Options' object has no attribute 'get_all_field_names'
egroeper commented 7 years ago

I had the same error using the latest released spyne version (2.12.14), but with current master everything works fine.

Perhaps a new version of spyne should be released and published on pypi?

igor-kremin commented 5 years ago

https://stackoverflow.com/questions/40212969/options-object-has-no-attribute-get-all-field-names Replace

unknown_fields_names = field_names.difference( 
    meta.get_all_field_names())

to

unknown_fields_names = field_names.difference(
    [f.name for f in meta.get_fields()])