trailofbits/algo · error · AttributeError

Error while checking if attributes should be changed

Error message

Error while checking if attributes should be changed

What it means

This error is raised when comparing the target server's current attributes against the wished (desired) configuration raises an AttributeError — typically because an expected key is missing from the API-returned server dict (target_server[key] or a nested dict attribute access fails) or a value is None where a dict was assumed.

Source

Thrown at library/scaleway_compute.py:586

    )
    compute_api.module.debug("Debug dict %s" % debug_dict)
    try:
        for key in PATCH_MUTABLE_SERVER_ATTRIBUTES:
            if key in target_server and key in wished_server:
                # When you are working with dict, only ID matter as we ask user to put only the resource ID in the playbook
                if (
                    isinstance(target_server[key], dict)
                    and wished_server[key]
                    and "id" in target_server[key].keys()
                    and target_server[key]["id"] != wished_server[key]
                ):
                    return True
                # Handling other structure compare simply the two objects content
                elif not isinstance(target_server[key], dict) and target_server[key] != wished_server[key]:
                    return True
        return False
    except AttributeError:
        compute_api.module.fail_json(msg="Error while checking if attributes should be changed")


def server_change_attributes(compute_api, target_server, wished_server):
    compute_api.module.debug("Starting patching server attributes")
    patch_payload = dict()

    for key in PATCH_MUTABLE_SERVER_ATTRIBUTES:
        if key in target_server and key in wished_server:
            # When you are working with dict, only ID matter as we ask user to put only the resource ID in the playbook
            if isinstance(target_server[key], dict) and "id" in target_server[key] and wished_server[key]:
                # Setting all key to current value except ID
                key_dict = dict((x, target_server[key][x]) for x in target_server[key].keys() if x != "id")
                # Setting ID to the user specified ID
                key_dict["id"] = wished_server[key]
                patch_payload[key] = key_dict
            elif not isinstance(target_server[key], dict):
                patch_payload[key] = wished_server[key]

View on GitHub (pinned to 20e22a8715)

Solutions

  1. Print/dump target_server and wished_server to find the missing key (add a debug task)
  2. Update the module's attribute comparison to use target_server.get(key) instead of direct indexing
  3. Pin to a known-good Scaleway API/module version if the response schema changed
  4. Ensure the server exists and is fully provisioned before running attribute changes

Example fix

// before
elif not isinstance(target_server[key], dict) and target_server[key] != wished_server[key]:
// after
elif not isinstance(target_server.get(key), dict) and target_server.get(key) != wished_server.get(key):
Defensive patterns

Strategy: validation

Validate before calling

# Verify required keys exist before comparing
missing = [k for k in wished if k not in (target or {})]
assert not missing, f'API response missing keys: {missing}'

Type guard

def has_keys(d: dict, keys: list[str]) -> bool:
    return isinstance(d, dict) and all(k in d for k in keys)

Prevention

When it happens

Trigger: server_attributes_should_be_changed iterates over wished_server keys and accesses target_server[key] / .get(...); if the fetched server JSON lacks an attribute (API version differences, stopped/archived servers omitting fields like 'image' or 'public_ip'), the attribute access throws AttributeError.

Common situations: Scaleway API responses changed shape between API versions, comparing against a server in 'stopped'/'archived' state that omits fields, or passing a malformed wished_server dict to the module.

Related errors


AI-assisted analysis of trailofbits/algo@20e22a8715 (2026-08-28). Data as JSON: /api/errors/cdb2469db6cc26b8. Report an issue: GitHub.