linode_api4-python icon indicating copy to clipboard operation
linode_api4-python copied to clipboard

NodebalancerNode not found.

Open israelriibeiro opened this issue 7 years ago • 9 comments

Hi, i was testing this, as describe in the documentation.

import linode

nb_node = linode.NodeBalancerNode(client, xxx, xxx, xxxx) # linode_client, node_id, config_id, nodebalancer_id
nb_node.weight = '100'
nb_node.save()

It returned this error:

Traceback (most recent call last): File "linode_script.py", line 26, in nb_node = linode.NodeBalancerNode(client, xxx, xxx, xxxx) # linode_client, node_id, config_id, nodebalancer_id AttributeError: module 'linode' has no attribute 'NodeBalancerNode'

What am i doing wrong?

Thanks.

israelriibeiro avatar Jan 31 '18 11:01 israelriibeiro

Looks like it's not you - I'm missing a like in my __init__.py. I'll get it fixed tonight, but until then you should be about to do a from linode.objects.nodebalancer.node import NodeBalancerNode - sorry. I'll update this when it's fixed.

Dorthu avatar Jan 31 '18 19:01 Dorthu

This should be fixed in v4.1.7b1 - do a pip install --upgrade linode-api or pull/rebuild to get the fix. Please let me know if it's resolved so I can close this item.

Dorthu avatar Feb 01 '18 12:02 Dorthu

@Dorthu , thanks. It went ok. But, it didn't update the weight. And save returns true, though.

israelriibeiro avatar Feb 01 '18 13:02 israelriibeiro

when I run the excerpt above, I get the following error:

ApiError: 400: must be of type Integer;

This is probably correct - try setting nb_node.weight = 100 (no quotes) and see if it works.

Dorthu avatar Feb 01 '18 15:02 Dorthu

Hmm.. actaully, what I ran was this:

import linode

nb_node = linode.NodeBalancerNode(client, xxx, xxx, xxxx) # linode_client, node_id, config_id, nodebalancer_id
nb_node.weight # checked what it was initially in my python shell
nb_node.weight = '100'
nb_node.save()

If I don't check it first, then I can reproduce the behavior you're seeing. I'm looking into it now.

Dorthu avatar Feb 01 '18 15:02 Dorthu

You're right. This time was mistake. I'll check it again. Sorry!

israelriibeiro avatar Feb 01 '18 16:02 israelriibeiro

@Dorthu , here a test that i did: Something strange happend: teste_api

israelriibeiro avatar Feb 01 '18 16:02 israelriibeiro

Yeah, I think this has something to do with how this library lazy-loads data - accessing an attribute of an api model class that hasn't been loaded yet will issue an api request and populate all attributes of the model (since they all come back). I think that setting the weight is not triggering it to be populated (correctly), but saving the model for some reason is triggering an api request/population, which overrides the values set previously (and thereby doesn't save anything). This is supported by the test you did (on line 28 you don't access any attributes of nb_node, and that node's weight didn't change, but on line 36 you do access an attribute, and that node's weight does change). I'm going to take a look at the code for saving objects and make sure it doesn't trigger a population in the process.

Thanks for the details, they made this a lot easier to identify.

Dorthu avatar Feb 01 '18 18:02 Dorthu

I reproduced this issue in the tests - it looks like this is unique to models that have a derived base class, or possibly unique only to NodeBalancerNode. I'm going to try to get a fix up shortly.

Dorthu avatar Feb 03 '18 01:02 Dorthu