Skip to content

Bug: User model #239

Open
Open

Description

@Eggwise

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`


Activity

  1. MariuszWisniewski commented on Sep 8, 2016

    @MariuszWisniewski
    Contributor

    @opalczynski Can you please take a look?

  2. opalczynski commented on Sep 8, 2016

    @opalczynski
    Contributor

    @lifcio will do.

  3. MariuszWisniewski commented on Sep 8, 2016

    @MariuszWisniewski
    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?

  4. opalczynski commented on Sep 8, 2016

    @opalczynski
    Contributor

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

  5. Eggwise commented on Sep 11, 2016

    @Eggwise
    Author

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

  6. MariuszWisniewski commented on Sep 11, 2016

    @MariuszWisniewski
    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)
  7. Eggwise commented on Sep 11, 2016

    @Eggwise
    Author

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

  8. added 4 commits that reference this issue on Sep 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions