NodebalancerNode not found.
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
What am i doing wrong?
Thanks.
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.
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 , thanks. It went ok. But, it didn't update the weight. And save returns true, though.
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.
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.
You're right. This time was mistake. I'll check it again. Sorry!
@Dorthu , here a test that i did:
Something strange happend:

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.
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.