Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: User model #239

Open
Eggwise opened this issue Aug 31, 2016 · 7 comments
Open

Bug: User model #239

Eggwise opened this issue Aug 31, 2016 · 7 comments
Assignees

Comments

@Eggwise
Copy link

Eggwise commented Aug 31, 2016

when trying to list the users in my instance (see following code)

syncano.connect(api_key=API_KEY)
users = User.please.list(instance_name=INSTANCE)
for user in users:
    # print(user)
    print(user.user_key)

I get the following error:

Traceback (most recent call last):
File "_**syncano_backend/test/test.py", line 34, in
for user in users:
File "/usr/local/lib/python3.5/dist-packages/syncano/models/manager.py", line 812, in iterator
yield self.serialize(o)
File "/usr/local/lib/python3.5/dist-packages/syncano/models/manager.py", line 741, in serialize
return model(__properties) if self._serialize else data
File "/usr/local/lib/python3.5/dist-packages/syncano/models/archetypes.py", line 90, in init
self.to_python(kwargs)
File "/usr/local/lib/python3.5/dist-packages/syncano/models/archetypes.py", line 247, in to_python
setattr(self, field.name, value)
File "/usr/local/lib/python3.5/dist-packages/syncano/models/fields.py", line 105, in set
instance.raw_data[self.name] = self.to_python(value)
File "/usr/local/lib/python3.5/dist-packages/syncano/models/fields.py", line 524, in to_python
return self.rel(
*value)
File "/usr/local/lib/python3.5/dist-packages/syncano/models/classes.py", line 145, in new
raise SyncanoValidationError('Field "instance_name" is required.')
syncano.exceptions.SyncanoValidationError: Field "instance_name" is required.

I tested my api key in http://docs.syncano.io/v0.1.1/docs/users-list and it worked. It looks like the python lib cant create a user model object from the response.

Code from the stacktrace


   def serialize(self, data, model=None):
        """Serializes passed data to related :class:`~syncano.models.base.Model` class."""
        model = model or self.model
        if data == '':
            return

        if isinstance(data, model):
            return data

        if not isinstance(data, dict):
            raise SyncanoValueError('Unsupported data type.')

        properties = deepcopy(self.properties)
        properties.update(data)
        return model(**properties) if self._serialize else data`


@MariuszWisniewski
Copy link
Contributor

@opalczynski Can you please take a look?

@opalczynski
Copy link
Contributor

@lifcio will do.

@MariuszWisniewski
Copy link
Contributor

Thanks! I checked and it works when we pass instance_name as a parameter in connect method, so maybe only our example in docs is wrong?

@opalczynski
Copy link
Contributor

Ahh, this. Yep this is known bug :) By me. But to be honest - I have no idea how to solve it now :(

@Eggwise
Copy link
Author

Eggwise commented Sep 11, 2016

Hi,
Ok, maybe i can fix the bug in my spare time.
thanks for the response.
Cheers

@MariuszWisniewski
Copy link
Contributor

@Eggwise Unless you need to connect to multiple Syncano instances in your app at once, you can try following code as a workaround for now (pass instance name in connect instead of list):

import syncano
from syncano.models import User

syncano.connect(api_key='KEY', instance_name=META['instance'])
users = User.please.list()
for user in users:
    # print(user)
    print(user.user_key)

@Eggwise
Copy link
Author

Eggwise commented Sep 11, 2016

@lifcio That is handy, thanks!
Maybe its good to update the documentation to prevent users from getting errors.

ilu2112 added a commit that referenced this issue Sep 15, 2016
ilu2112 added a commit that referenced this issue Sep 15, 2016
ilu2112 added a commit that referenced this issue Sep 15, 2016
ilu2112 added a commit that referenced this issue Sep 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants