-
-
Notifications
You must be signed in to change notification settings - Fork 113
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
Getting one value from a Choice invalidates other values as a side effect #179
Comments
That's a fair point! The behavior you observe is such to account for possible inner structures such as:
If
I totally agree that what's happening now is weird. Any better ideas? |
We've just been affected by this. It seems to me that if value is not noValue: # Add this condition
self._currentIdx = idx
if oldIdx is not None and oldIdx != idx:
self._componentValues[oldIdx] = noValue I don't know if that might have other side-effects though, but it seems logical to me that setting a component of Choice to |
...although that would probably mean For Choice, perhaps it would be reasonable to change the current component if the new value is not If just trying to find the one currently set component (as in the original report here), I notice that its name and value can be obtained via I'm not sure if there might be cases where it's useful to get the other components even if they are schemas rather than values, but it looks like |
Hi,
I stumbled upon this bug:
You see that the first time
bar
is accessed, it returns the correct value.The second time it returns a schema object instead, which is triggered by accessing
foo
.I traced the cause of this problem to the implementation of
Choice.setComponentByPosition
:pyasn1/pyasn1/type/univ.py
Lines 3121 to 3122 in d0b7f2e
This method remembers
oldIdx
, which is the last index that has been set, and when you set another index, it resets the previous index tonoValue
(which will later be turned into a schema object). The methodsetComponentByPosition
is called fromgetComponentByPosition
here:pyasn1/pyasn1/type/univ.py
Lines 2500 to 2501 in 40d5a7f
I believe the implementation of the
oldIdx
handling should be changed or it should not be called like this fromgetComponentByPosition
.The reason I was accessing all of the component values in a
Choice
is that I was usingobj['foo'].hasValue()
to find the one value that is defined.The text was updated successfully, but these errors were encountered: