Skip to content

add_group_member and delete_group_member raise FossologyApiError on success responses #179

@Valyrian-Code

Description

@Valyrian-Code

Describe the bug

Fossology.add_group_member and Fossology.delete_group_member raise FossologyApiError on successful API responses. The endpoints return 201 Created and 202 Accepted respectively, but the library only checks for 200. Both successful responses fall through to the catch-all else branch and get treated as errors.

This is internally inconsistent with the same file: delete_group at fossology/groups.py:95 correctly accepts 202, proving the codebase already knows non-200 success codes happen.

Reproduction

Against Fossology 4.4.0 / API 1.6.2 (latest fossology/fossology Docker image):

import fossology, secrets, requests
from fossology.enums import TokenScope

URL = "http://localhost/repo"
token = fossology.fossology_token(URL, "fossy", "fossy", secrets.token_urlsafe(8), TokenScope.WRITE)
foss = fossology.Fossology(URL, token)
h = {"Authorization": f"Bearer {token}"}

# Create a fresh group and user, then add the user to the group
foss.create_group("DemoGroup")
gid = next(g.id for g in foss.list_groups() if g.name == "DemoGroup")
spec = {"id":0,"name":"DemoUser","description":"","email":"d@e.com","accessLevel":"read_write",
        "rootFolderId":1,"emailNotification":"y",
        "agents":{"bucket":True,"copyright_email_author":True,"ecc":True,"keyword":True,
                  "mimetype":False,"monk":True,"mime":True,"nomos":True,"ojo":True,
                  "package":True,"specific_agent":True}}
foss.create_user(spec)
uid = next(u.id for u in foss.list_users() if u.name == "DemoUser")

foss.add_group_member(gid, uid)
# fossology.exceptions.FossologyApiError: An error occurred while adding user N to group M:
#   User added to group. (201)

The library reports an error message that literally says "User added to group" — the operation succeeded.

Status code mismatch (verified live)

Library function Library accepts API returns OK?
list_groups 200 200
list_group_members 200 200
create_group 200 200
delete_group 202 202
add_group_member 200 201
delete_group_member 200 202

Raw HTTP traces confirming the response codes:

POST   /groups/{gid}/user/{uid}   -> 201  {"code":201,"message":"User added to group.","type":"INFO"}
DELETE /groups/{gid}/user/{uid}   -> 202  {"code":202,"message":"User will be removed from group.","type":"INFO"}

Affected tests on a clean clone

Running the test suite against a fresh Fossology 4.4.0 container, three group tests fail because of this single root cause:

FAILED tests/test_groups.py::test_list_group_members
FAILED tests/test_groups.py::test_add_group_member_if_member_already_exists_returns_400
FAILED tests/test_groups.py::test_delete_group_member

(test_list_group_members and test_delete_group_member fail at fixture setup, when add_group_member raises before they get to assert anything.)

Proposed fix

Two-line change in fossology/groups.py:

-        if response.status_code == 200:
+        if response.status_code == 201:
             logger.info(f"User {user_id} has been added to group {group_id}.")
-        if response.status_code == 200:
+        if response.status_code == 202:
             logger.info(f"User {user_id} will be removed from group {group_id}.")

Locally verified — all 12 tests in tests/test_groups.py pass after the change, no other test regresses. Happy to open a PR if you'd like.

Environment

  • fossology-python version: 3.5.0 (main)
  • Fossology server: 4.4.0 / API 1.6.2 (fossology/fossology:latest Docker image)
  • Python: 3.13

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions