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] API endpoints are failing with "Organization not found, organization_field not implemented correctly." #105

Open
nemesifier opened this issue May 17, 2021 · 3 comments
Labels
enhancement New feature or request Hacktoberfest Easy issues for attracting Hacktoberfest participants.

Comments

@nemesifier
Copy link
Member

nemesifier commented May 17, 2021

The following API endpoints:

  • /api/v1/ip-address/<id>/
  • /api/v1/subnet/<id>/

Are failing when using the latest version of openwisp-users, with the error:

Organization not found, `organization_field` not implemented correctly.

However, the bug is not showing in tests, so I'm puzzled by this and I would like to know if anyone can confirm this.

@nemesifier nemesifier added the enhancement New feature or request label May 17, 2021
@nemesifier nemesifier added the Hacktoberfest Easy issues for attracting Hacktoberfest participants. label Oct 1, 2021
@pandafy pandafy added this to the Release 0.3.0 milestone Jan 26, 2022
@aagmanbhatt
Copy link

aagmanbhatt commented Feb 14, 2022

These end points have changed to :
/api/v1/ipam/ip-address/<id>/
/api/v1/ipam/subnet/<id>/

and I am unable to replicate this error

@DavidMeu
Copy link

DavidMeu commented Mar 6, 2022

Reproduced in my end:
Created a subnet with empty organization field (null).
curl -X POST "<URL>/api/v1/ipam/subnet/" -H "Authorization: Bearer some token" -d "subnet=10.0.0.0/24&organization="
And tried deleting it:
curl -X DELETE "<URL>/api/v1/ipam/subnet/6d003f5a-df3d-4a57-b136-78f97a3e48b3/" -H "Authorization: Bearer some token"

And got:
AttributeError: Organization not found, organization_field not implemented correctly.

*master branch
*When applying the creation+deletion via the admin site it is ok

Trace:

  File "\venv\lib\site-packages\openwisp_users\api\permiss
ions.py", line 13, in has_object_permission
    organization = self.get_object_organization(view, obj)
  File "\venv\lib\site-packages\openwisp_users\api\permiss
ions.py", line 26, in get_object_organization
    raise AttributeError(

Exception Type: AttributeError at /api/v1/ipam/subnet/98781c63-c6dd-4375-a783-1609a90740df/
Exception Value: Organization not found, `organization_field` not implemented correctly.

@aagman945 on what version you tried replicate this issue?

@praptisharma28
Copy link
Member

When I tried to reproduce this error:

(venv-ipam) prapti@prapti:~/Desktop/openwisp/openwisp-ipam/tests$ curl -v -X POST "http://127.0.0.1:8000/api/v1/ipam/subnet/" \27.0.0.1:8000/api/v1/ipam/subnet/" \
     -H "Authorization: Bearer 961b450e4f327b661e86a89937c81a0ec5abfc9d" \
     -H "Content-Type: application/x-www-form-urlencoded" \
     -d "name=Test Subnet&subnet=10.0.0.0/24&organization="
Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 127.0.0.1:8000...
* Connected to 127.0.0.1 (127.0.0.1) port 8000 (#0)
> POST /api/v1/ipam/subnet/ HTTP/1.1
> Host: 127.0.0.1:8000
> User-Agent: curl/7.81.0
> Accept: */*
> Authorization: Bearer 961b450e4f327b661e86a89937c81a0ec5abfc9d
> Content-Type: application/x-www-form-urlencoded
> Content-Length: 49
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 201 Created
< Date: Fri, 01 Nov 2024 14:12:28 GMT
< Server: WSGIServer/0.2 CPython/3.10.12
< Content-Type: application/json
< Vary: Accept
< Allow: GET, POST, HEAD, OPTIONS
< X-Frame-Options: DENY
< Content-Length: 228
< X-Content-Type-Options: nosniff
< Referrer-Policy: same-origin
< Cross-Origin-Opener-Policy: same-origin
< 
* Connection #0 to host 127.0.0.1 left intact
{"id":"533bb1c1-02d1-4542-8467-8bd963ab3eb5","created":"2024-11-01T14:12:28.621520Z","modified":"2024-11-01T14:12:28.621520Z","name":"Test Subnet","subnet":"10.0.0.0/24","description":"","organization":null,"master_subnet":null}(venv-ipam) prapti@prapti:~/Desktop/openwisp/openwisp-ipam/tests$ curl -v -X DELETE "http://127.0.0.1:8000/api/v1/ipam/subnet/533bb1c1-02d1-4542-8467-8bd963ab3eb5/" \                              curl -v -X DELETE "http://127.0.0.1:8000/api/v1/ipam/subnet/533bb1c1-02d1-4542-8467-8bd963ab3eb5/" \
     -H "Authorization: Bearer 961b450e4f327b661e86a89937c81a0ec5abfc9d"
*   Trying 127.0.0.1:8000...
* Connected to 127.0.0.1 (127.0.0.1) port 8000 (#0)
> DELETE /api/v1/ipam/subnet/533bb1c1-02d1-4542-8467-8bd963ab3eb5/ HTTP/1.1
> Host: 127.0.0.1:8000
> User-Agent: curl/7.81.0
> Accept: */*
> Authorization: Bearer 961b450e4f327b661e86a89937c81a0ec5abfc9d
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 204 No Content
< Date: Fri, 01 Nov 2024 14:12:53 GMT
< Server: WSGIServer/0.2 CPython/3.10.12
< Vary: Accept, Cookie
< Allow: GET, PUT, PATCH, DELETE, HEAD, OPTIONS
< X-Frame-Options: DENY
< Content-Length: 0
< X-Content-Type-Options: nosniff
< Referrer-Policy: same-origin
< Cross-Origin-Opener-Policy: same-origin
< 
* Connection #0 to host 127.0.0.1 left intact
(venv-ipam) prapti@prapti:~/Desktop/openwisp/openwisp-ipam/tests$ 

I was able to delete it successfully.
Can we confirm this issue ? @nemesifier @pandafy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Hacktoberfest Easy issues for attracting Hacktoberfest participants.
Projects
Status: To do (Python & Django)
Development

No branches or pull requests

5 participants