Skip to content

Bug: _generate_node_id fallback may silently use hostname when ansible_name field absent from NodeCreate #2175

@mrveiss

Description

@mrveiss

Problem

PR #2146 (#1936) changed `_generate_node_id()` to use `getattr(node_data, "ansible_name", None)` as the preferred hash source. However, if `NodeCreate` does not have `ansible_name` as a field (it was added in PR #1932 but only to `NodeUpdate`, not necessarily `NodeCreate`), `getattr` silently returns `None` and falls through to `ip_address` or `hostname`.

This means the fix may be ineffective if `NodeCreate` never has `ansible_name` set — the function would always fall through to the same hostname-based hash as before.

Discovered During

Implementation of #1936 fix during batch 3.

Suggested Fix

Verify `NodeCreate` schema includes `ansible_name` as an optional field. If not, add it. Or check if the enrollment API sets it before `_generate_node_id` is called.

Impact

Low — most enrollments provide explicit `node_id`, so the fallback is rarely used.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions