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

Remove status attribute requirement when state is present #298

Merged
merged 4 commits into from
Jan 10, 2024

Conversation

Dav-C
Copy link

@Dav-C Dav-C commented Dec 21, 2023

Closes #251

Remove the status field requirement when state is present. This should eliminate the need to provide a status when updating non-status fields on an existing record.

@Dav-C Dav-C changed the title Update status attribute Remove status attribute requirement when state is present Dec 21, 2023
@whitej6
Copy link

whitej6 commented Dec 21, 2023

Thoughts on validating when self.nb_object is empty and status in arg spec but was not provided, the raising an error instead of relying on a traceback from pynautobot.

@joewesch
Copy link
Contributor

joewesch commented Dec 21, 2023

You missed one in the device_interface module.

@Dav-C
Copy link
Author

Dav-C commented Dec 21, 2023

Thoughts on validating when self.nb_object is empty and status in arg spec but was not provided, the raising an error instead of relying on a traceback from pynautobot.

If I understand correctly, this would mean updating this check for all required fields not just status. With the change in this PR, if you attempt to create a record without a required status field this is the result, which I think is pretty clear.

TASK [Create a Nautobot Rack] ******************************************************************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "{\"status\":[\"This field is required.\"]}"}

@joewesch
Copy link
Contributor

Honestly, looking at the code closer I think we should remove every required_if all together. None of the parameters are truly required on updates that aren't set as required=True in the argspec - which just makes the required_if redundant.

@Dav-C
Copy link
Author

Dav-C commented Dec 21, 2023

Honestly, looking at the code closer I think we should remove every required_if all together. None of the parameters are truly required on updates that aren't set as required=True in the argspec - which just makes the required_if redundant.

I agree that it makes sense to remove it in most cases. There are some I'm not so sure about, however. Locations for example require an id if the state is absent, which I assume is to prevent deleting multiple locations with the same name.

@joewesch
Copy link
Contributor

Honestly, looking at the code closer I think we should remove every required_if all together. None of the parameters are truly required on updates that aren't set as required=True in the argspec - which just makes the required_if redundant.

I agree that it makes sense to remove it in most cases. There are some I'm not so sure about, however. Locations for example require an id if the state is absent, which I assume is to prevent deleting multiple locations with the same name.

Good catch, yes.

@joewesch
Copy link
Contributor

I guess I should have clarified, I don't think we need any required_if on present states.

@Dav-C
Copy link
Author

Dav-C commented Dec 21, 2023

PR updated to remove all references to required_if state is present

@whitej6
Copy link

whitej6 commented Dec 22, 2023

Thoughts on validating when self.nb_object is empty and status in arg spec but was not provided, the raising an error instead of relying on a traceback from pynautobot.

If I understand correctly, this would mean updating this check for all required fields not just status. With the change in this PR, if you attempt to create a record without a required status field this is the result, which I think is pretty clear.

TASK [Create a Nautobot Rack] ******************************************************************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "{\"status\":[\"This field is required.\"]}"}

Looks good to me, I thought possibly it would be a python traceback. The message provided is good. :-)

Copy link
Contributor

@joewesch joewesch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you!

@joewesch joewesch merged commit 8b13345 into nautobot:develop Jan 10, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Status is required for updates
3 participants