-
Notifications
You must be signed in to change notification settings - Fork 81
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
servicenow.itsm.configuration_item is hard-coded to look in whole 'cmdb_ci' class when not query_sys_id #404
Comments
My suggested solution would be to update the following: configuration_item.pyif not query_sys_id:
+ cmdb_table = module.params["sys_class_name"] or "cmdb_ci"
- configuration_item = table_client.get_record("cmdb_ci", query_name)
+ configuration_item = table_client.get_record(cmdb_table, query_name)
# User did not specify existing CI, so we need to create a new one.
if not configuration_item:
- cmdb_table = module.params["sys_class_name"] or "cmdb_ci"
new = mapper.to_ansible(
table_client.create_record(
cmdb_table, mapper.to_snow(payload), module.check_mode
)
) |
@EUCTechTopics Hello, |
Hi @tupyy That does not provide the solution I need because I am not trying to query a table. The issue is that I am trying to update an existing CI by referencing its name. However, because there are multiple CI's with the same name in different classes, the module fails to find a unique CI to update. Please take a close look at my suggested code change and you shall see what I mean. |
I have updated the OP to make this more clear as well. |
From my understanding sysclass_name means table.
|
Yeah that is correct. This way when you want to update an existing record by referencing its name, it searches for that record only in the given table (sys_class_name). |
Ok, then why is this not working for you:
The problem with your PR is that is making |
Hi @tupyy Thanks for your follow-up. I understand your point about the flexibility of the sys_class_name parameter and that it essentially represents a table. However, the issue isn't about querying a generic table, but rather about how the existing module behavior handles updating Configuration Items (CIs) based on their names. The ProblemIn scenarios where multiple CIs exist with the same name but belong to different classes, the current module implementation fails to correctly identify the CI to update. This happens because the module defaults to querying the entire cmdb_ci class rather than the specific class provided by sys_class_name. This is problematic because it can lead to either:
My Proposed ChangeThe purpose of my proposed change is to ensure that the search for the CI is limited to the specific class (or table) provided by sys_class_name. By passing cmdb_table (which represents the sys_class_name) to the get_record method, the module will correctly narrow down the search to the intended class, preventing it from querying the entire cmdb_ci class. Why the Current API Call Suggestion Won’t WorkThe example you provided with servicenow.itsm.api_info does allow querying a specific table using sysparm_query. However, this approach is unrelated to the context of my issue, which specifically deals with the behavior of updating existing CIs by name in the current module. My PR doesn't just change the name of the table passed to table_client — it fixes a logic error that could lead to incorrect records being selected when multiple CIs share the same name across different classes. Configuration Item SpecificityRegarding your concern about making configuration_item generic: the proposed change actually improves specificity. It ensures that when updating or referencing a CI by name, the module is operating within the correct context (i.e., the correct class or table). The risk of incorrectly fetching or updating a CI from a different class is mitigated by this change. Thanks again for your attention to this matter! |
Hi @tupyy I’ve identified another critical issue related to this behavior: Additional ProblemWhen a Configuration Item (CI) with the specified name does not exist in the provided sys_class_name (table), but it does exist in another class (or table), the current implementation mistakenly updates the CI found in the wrong class. This is not the expected behavior. Expected BehaviorIf no CI with the given name exists in the specified sys_class_name, the module should create a new record in the provided class, not update an existing CI from a different class. Current Behavior
Proposed FixThe change I proposed earlier will also address this issue. By ensuring that the module only searches within the specified sys_class_name, it will correctly:
This will align the module’s behavior with user expectations and prevent potentially harmful updates to CIs in unintended classes. Thank you for considering this additional concern. I’m confident that the proposed changes will significantly improve the module’s reliability and accuracy. |
Hi @tupyy Following our discussion and your feedback, I reviewed your concern regarding the potential for setting sys_class_name as for example "incident", which could make the query less specific to the CMDB. To address this, I've updated the query to include sys_class_name. This change ensures that we continue to use the table_client specifically on the cmdb_ci table while extending the filter to incorporate sys_class_name. Please review the updated PR #405 and let me know if these adjustments better align with your expectations. |
Hello, Thank you for the PR. After some discussion, we would like to keep the changes very simple. It is something like your first suggestion. If the
As you can see, we need the same fix for WDYT |
sorry for the long radio silence, i will take a look at this and come back with an updated pull request :) |
Created PR #413 |
SUMMARY
When trying to update an existing CI by referencing its name, the get_record method in the configuration_item function retrieves records from the entire cmdb_ci class instead of limiting the query to the specific class defined in sys_class_name. This can lead to incorrect or unintended records being retrieved when the user specifies a different class through the sys_class_name parameter.
ISSUE TYPE
COMPONENT NAME
servicenow.itsm.configuration_item
ANSIBLE VERSION
COLLECTION VERSION
CONFIGURATION
OS / ENVIRONMENT
STEPS TO REPRODUCE
EXPECTED RESULTS
ACTUAL RESULTS
The text was updated successfully, but these errors were encountered: