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

NodebalancerNode not found. #97

Closed
israelriibeiro opened this issue Jan 31, 2018 · 9 comments · Fixed by #277
Closed

NodebalancerNode not found. #97

israelriibeiro opened this issue Jan 31, 2018 · 9 comments · Fixed by #277

Comments

@israelriibeiro
Copy link

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.

@Dorthu
Copy link
Member

Dorthu commented Jan 31, 2018

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
Copy link
Member

Dorthu commented Feb 1, 2018

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.

@israelriibeiro
Copy link
Author

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

@Dorthu
Copy link
Member

Dorthu commented Feb 1, 2018

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
Copy link
Member

Dorthu commented Feb 1, 2018

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.

@israelriibeiro
Copy link
Author

israelriibeiro commented Feb 1, 2018

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

@israelriibeiro
Copy link
Author

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

@Dorthu
Copy link
Member

Dorthu commented Feb 1, 2018

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 added a commit that referenced this issue Feb 3, 2018
This reproduces the issue described in #97, when saving an unpopulated
object apparently triggers population before sending the PUT request.
Fix coming soon.
@Dorthu
Copy link
Member

Dorthu commented Feb 3, 2018

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.

ezilber-akamai-zz added a commit that referenced this issue May 9, 2023
)

## 📝 Description

Previously, attempting to update a non-populated NodeBalancerNode would
result in the update actually updating the resource silently. This
change fixes the issue.

## ✔️ How to Test

`pytest test`

Note: Since this change deals with making updates to real resources as
opposed to fixtures, it cannot be tested using mocks and must therefore
be tested manually. To do this, first create a NodeBalancerNode in your
Linode account if one does not already exist, and then run this python
script and verify that the weight of the node was actually updated.

```
#!/usr/bin/env python3

from linode_api4 import LinodeClient
from linode_api4.objects import  NodeBalancerNode

client = LinodeClient(<personal_access_token>)

node = NodeBalancerNode(client, <node_id>, <config_id>, <nodebalancer_id>)

node.weight = 60

node.save()
```

Resolves #97
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants
@israelriibeiro @Dorthu and others