-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Fixes: #15016 - Catch AssertionError from cable trace and throw ValidationError #16384
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of assert
statements in this logic was primarily for sanity-checking during initial development; they shouldn't be relied upon as true validation checks. (They aren't even run when __debug__
is False.)
If the use case in #15016 is not supported, we need to add specific validation logic to check for and report on it.
This PR has been automatically marked as stale because it has not had recent activity. It will be closed automatically if no further action is taken. |
…of a validation error.
This PR has been automatically marked as stale because it has not had recent activity. It will be closed automatically if no further action is taken. |
This PR has been automatically marked as stale because it has not had recent activity. It will be closed automatically if no further action is taken. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid this still doesn't address my primary concern: Validation of cable state needs to be performed prior to the point where we're generating cable paths. (Again, the original assertions were just sanity checks.) This should ideally be performed on each model under clean()
.
Additionally, as a rule generic views should not check for and handle any model-specific exceptions.
The issue is there isn't really a way to validate the cable state prior to the cable being saved, without effectively duplicating all the work done in the cable path generation. The main reason for this is because a lot of these assertion checks are dependant on sibling cable state further down the path, not just part of the existing cable save, which isn't known until you generate the full path. We would effectively be running the from_origin twice in this instance, once to validate the cable state and once to save it. Take for example this path, where Switch 1, interface1 is what you are connecting (the rest is fully formed):
You can validate FP1-1 and FP1-2 because they are connected. But you can't run any of the peer validations on FP2-1 and FP2-2 because FP2-1 doesn't know that FP2-2 will be part of that same path until Interface1 is connect and that path is fully formed. I can take another pass at it, and see if I can have it run this in clean() first, but most of the parts of this rely on objects existing in the database already as well, so this would likely need a complete re-write, which I was trying to avoid doing. |
This PR has been automatically marked as stale because it has not had recent activity. It will be closed automatically if no further action is taken. |
This PR has been automatically marked as stale because it has not had recent activity. It will be closed automatically if no further action is taken. |
…into 15016-fix-assertionerror-when-saving-cable
This is now ready. I stupidly missed an UnsupportedCablePath in the test instead of AbortRequest |
This PR has been automatically marked as stale because it has not had recent activity. It will be closed automatically if no further action is taken. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dan, can you please rebase to main
One more @DanSheps when I switch to this branch NetBox won't start with the following error - can you please sync and try:
|
…o 15016-fix-assertionerror-when-saving-cable
Merged in main. Started clean for me either way but hopefully this corrects whatever you are hitting. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dcim.model.cables.CablePath.from_origin() is called from dcim.utils.create_cablepath which is called from wireless.signals.update_connected_interfaces in a post_save handler. This would be an issue as it could raise an error post_save so it would already be saved in this incorrect state.
I agree with Jeremy's prior comment that I think we need to validate it before save. Seems like we would want to create the connection graph in memory and then validate that... which sounds like a big pain.
Short of re-writing the whole thing, I don't know if we can write it in-memory as-is due to some of the queries that are run against it. The signals will all fire inside of a transaction which should be rolled back automatically if there is an error. I don't think there is a data consistency concern here, it would be treated the same as if the exception is raise directly in save (the transaction would roll back and you would be presented with the form again). |
I think catching that is a separate issue and I think we can wrap that in this PR as it is similar. Let me go add that and see if I can adjust to catch that as well. |
also, do you have an easier repro scenario for the original cable error? |
Unfortunately no |
From message " it's been too long since I looked at it. If you're comfortable dismissing the old review, it's fine with me"
Fixes: #15016 - Catch AssertionError from cable trace and throw ValidationError