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

ListConfig.__setitem__(slice, ...) does not roll-back cfg state upon mutation failure #950

Closed
Jasha10 opened this issue May 26, 2022 · 0 comments · Fixed by #975
Closed
Assignees
Labels
bug Something isn't working

Comments

@Jasha10
Copy link
Collaborator

Jasha10 commented May 26, 2022

Most mutations to OmegaConf containers are atomic in the sense that a failed mutation will result in an unmodified object. This is not the case, however, when ListConfig.__setitem__ is called on a slice.

To Reproduce
The last line of the script below demonstrates inconsistency (failure to roll-back ListConfig state on failed mutation).

from pytest import raises

from omegaconf import OmegaConf, UnsupportedValueType

illegal = object()

cfg = OmegaConf.create([1, 2, 3])

with raises(UnsupportedValueType):
    cfg.append(illegal)
assert cfg == [1, 2, 3]

with raises(UnsupportedValueType):
    cfg.extend([illegal])
assert cfg == [1, 2, 3]

with raises(UnsupportedValueType):
    cfg.insert(1, illegal)
assert cfg == [1, 2, 3]

with raises(UnsupportedValueType):
    cfg[1] = illegal
assert cfg == [1, 2, 3]

with raises(UnsupportedValueType):
    cfg[1:2] = [illegal]
assert cfg == [1, 3]  # Inconsistent

Expected behavior
The last line above should be assert cfg == [1, 2, 3]

@Jasha10 Jasha10 added the bug Something isn't working label May 26, 2022
@Jasha10 Jasha10 changed the title Inconsistent ListConfig.__setitem__ behavior on failure ListConfig.__setitem__(slice, ...) does not roll-back cfg state upon mutation failure May 26, 2022
@pixelb pixelb self-assigned this Jul 7, 2022
pixelb added a commit to pixelb/omegaconf that referenced this issue Jul 14, 2022
* omegaconf/listconfig.py (__setitem__): Operate on a copy
so any changes due to validation errors etc. are discarded.
Fixes issue omry#950
pixelb added a commit to pixelb/omegaconf that referenced this issue Jul 14, 2022
* omegaconf/listconfig.py (__setitem__): Operate on a copy
so any changes due to validation errors etc. are discarded.
Fixes issue omry#950
@Jasha10 Jasha10 linked a pull request Jul 14, 2022 that will close this issue
pixelb added a commit to pixelb/omegaconf that referenced this issue Jul 28, 2022
* omegaconf/listconfig.py (__setitem__): Operate on a copy
so any changes due to validation errors etc. are discarded.
* tests/test_basic_ops_list.py: Veryify list unchanged upon exception,
and specifically upon failure to insert.
Fixes issue omry#950
pixelb added a commit to pixelb/omegaconf that referenced this issue Aug 2, 2022
* omegaconf/listconfig.py (__setitem__): Operate on a copy
so any changes due to validation errors etc. are discarded.
* tests/test_basic_ops_list.py: Veryify list unchanged upon exception,
and specifically upon failure to insert.
Fixes issue omry#950
pixelb added a commit to pixelb/omegaconf that referenced this issue Aug 3, 2022
* omegaconf/listconfig.py (__setitem__): Operate on a copy
so any changes due to validation errors etc. are discarded.
* tests/test_basic_ops_list.py: Veryify list unchanged upon exception,
and specifically upon failure to insert.
Fixes issue omry#950
pixelb added a commit that referenced this issue Aug 3, 2022
* omegaconf/listconfig.py (__setitem__): Operate on a copy
so any changes due to validation errors etc. are discarded.
* tests/test_basic_ops_list.py: Veryify list unchanged upon exception,
and specifically upon failure to insert.
Fixes issue #950
Jasha10 pushed a commit to Jasha10/omegaconf that referenced this issue Aug 10, 2022
* omegaconf/listconfig.py (__setitem__): Operate on a copy
so any changes due to validation errors etc. are discarded.
* tests/test_basic_ops_list.py: Veryify list unchanged upon exception,
and specifically upon failure to insert.
Fixes issue omry#950
Jasha10 pushed a commit that referenced this issue Aug 10, 2022
* omegaconf/listconfig.py (__setitem__): Operate on a copy
so any changes due to validation errors etc. are discarded.
* tests/test_basic_ops_list.py: Veryify list unchanged upon exception,
and specifically upon failure to insert.
Fixes issue #950
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants