Skip to content

[GCU] Different apply-patch runs should produce same sorted steps#1988

Merged
ghooo merged 1 commit intosonic-net:masterfrom
ghooo:dev/mghoneim/changes_consistency
Dec 27, 2021
Merged

[GCU] Different apply-patch runs should produce same sorted steps#1988
ghooo merged 1 commit intosonic-net:masterfrom
ghooo:dev/mghoneim/changes_consistency

Conversation

@ghooo
Copy link
Contributor

@ghooo ghooo commented Dec 25, 2021

What I did

Fixes #1976

Different runs of apply-patch would produce different sorted steps. It is better to be consistent while producing the sorted steps to make it easier to debug issues in the future.

The issue is with using set(list) to remove duplicates from the list. Looping over the set elements does not guarantee same order every time we iterate. To reproduce this do the following:

  1. Create a file named test.py with the content
x = ["XYZ", "ABC", "DEF"]
y = set(x)
print(y)
  1. Run python3 test.py
  2. Again python3 test.py
  3. Again python3 test.py
    The output of these runs will be different each time.

How I did it

Instead of returning a set, return a list of ref_paths which does not have duplicated elements inserted to begin with.

How to verify it

unit-tests

Previous command output (if the output of a command-line utility has changed)

New command output (if the output of a command-line utility has changed)

@ghooo ghooo force-pushed the dev/mghoneim/changes_consistency branch from 93d2538 to 6ab8deb Compare December 25, 2021 17:26
@ghooo ghooo merged commit a98858d into sonic-net:master Dec 27, 2021
judyjoseph pushed a commit that referenced this pull request Jan 9, 2022
)

#### What I did
Fixes #1976

Different runs of `apply-patch` would produce different sorted steps. It is better to be consistent while producing the sorted steps to make it easier to debug issues in the future.

The issue is with using `set(list)` to remove duplicates from the list. Looping over the set elements does not guarantee same order every time we iterate. To reproduce this do the following:
1. Create a file named `test.py` with the content
```python
x = ["XYZ", "ABC", "DEF"]
y = set(x)
print(y)
```
2. Run `python3 test.py`
3. Again `python3 test.py`
4. Again `python3 test.py`
The output of these runs will be different each time.

#### How I did it
Instead of returning a `set`, return a list of `ref_paths` which does not have duplicated elements inserted to begin with.

#### How to verify it
unit-tests

#### Previous command output (if the output of a command-line utility has changed)

#### New command output (if the output of a command-line utility has changed)
dbarashinvd pushed a commit to dbarashinvd/sonic-utilities that referenced this pull request Jul 11, 2022
…nic-net#1988)

#### What I did
Fixes sonic-net#1976

Different runs of `apply-patch` would produce different sorted steps. It is better to be consistent while producing the sorted steps to make it easier to debug issues in the future.

The issue is with using `set(list)` to remove duplicates from the list. Looping over the set elements does not guarantee same order every time we iterate. To reproduce this do the following:
1. Create a file named `test.py` with the content
```python
x = ["XYZ", "ABC", "DEF"]
y = set(x)
print(y)
```
2. Run `python3 test.py`
3. Again `python3 test.py`
4. Again `python3 test.py`
The output of these runs will be different each time.

#### How I did it
Instead of returning a `set`, return a list of `ref_paths` which does not have duplicated elements inserted to begin with.

#### How to verify it
unit-tests

#### Previous command output (if the output of a command-line utility has changed)

#### New command output (if the output of a command-line utility has changed)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[GCU] PatchSorter.sort can generate different correct sorted steps for the same input -- always generate same steps

3 participants