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

Added +1 to the end in random filter so that it was inclusive #27215

Merged
merged 1 commit into from
Jan 26, 2018

Conversation

zerkms
Copy link
Contributor

@zerkms zerkms commented Jul 23, 2017

SUMMARY

This PR addresses #27214

The documentation states that the end fraction of the random filter is inclusive, so I believe it's safe to assume everybody who read the documentation relied on it, so this change is not a breaking change.

Fixes #27214

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

core
filters

ANSIBLE VERSION
ansible 2.3.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4]
ADDITIONAL INFORMATION

@ansibot ansibot added affects_2.4 This issue/PR affects Ansible v2.4 bugfix_pull_request c:plugins/filter needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Jul 23, 2017
@jborean93 jborean93 removed the needs_triage Needs a first human triage before being processed. label Jul 25, 2017
@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Aug 2, 2017
@ansibot ansibot added the new_contributor This PR is the first contribution by a new community member. label Oct 18, 2017
@ansibot ansibot removed the new_contributor This PR is the first contribution by a new community member. label Nov 3, 2017
@maxamillion maxamillion merged commit ea2b89c into ansible:devel Jan 26, 2018
Lujeni pushed a commit to Lujeni/ansible that referenced this pull request Feb 1, 2018
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bugfix_pull_request labels Mar 6, 2018
@JamesUoM
Copy link

SUMMARY

The documentation states that the end fraction of the random filter is inclusive, so I believe it's safe to assume everybody who read the documentation relied on it, so this change is not a breaking change.

Well the Ansible docs didn't make it clear whether it was inclusive or not and I tested it on 2.3 and found that it wasn't and wrote my task accordingly. I got the docs changed to imply it was between not inclusive. #33226. Now you've changed it to be inclusive but not reverted the docs.

Finally as this was a change in behaviour rather than bug fix it should have been in the porting notes.

@maxamillion
Copy link
Contributor

@zerkms we need a docs fix ^^^

@bcoca
Copy link
Member

bcoca commented Oct 10, 2018

@maxamillion no, i think we need to return to the documented behaviour, since it was already 'documented' and it is not backwards compatible

@maxamillion
Copy link
Contributor

@bcoca alright, want me to revert?

@bcoca
Copy link
Member

bcoca commented Oct 10, 2018

yep, original issue was already fixed by the 'doc update' and this ends up creating more issues instead

if you want to add new switch to be 'inclusive=false|true' to allow for both behaviors while being backwards compatible, even better.

@zerkms
Copy link
Contributor Author

zerkms commented Oct 10, 2018

The original documentation in its examples implied it's inclusive.

People relied on what was documented. Changing documentation is a breaking change, this PR does not BC anything, it just fixes code to align with the documentation.

#33226 - is a breaking change

For instance

"{{ 59 |random}} * * * * root /script/from/cron"

this is a valid example from the doc. For those who trusted it and implemented it like that - they expected to have an even distribution of the random numbers for the whole hour, if this PR is unmerged - all those people would lose one last minute of an hour. One cannot simply change the documentation.

Another example:

"{{ ['a','b','c']|random }}"
{{ 101 |random(step=10) }}

(now) The first line is inclusive, the second is exclusive. WAT.

@zerkms zerkms deleted the ISSUE-27214 branch October 10, 2018 19:30
@bcoca
Copy link
Member

bcoca commented Oct 10, 2018

but it will break existing playbooks that rely on it NOT being inclusive, the docs were fixed as they were incorrect and didn't clearly state how it worked.

@zerkms
Copy link
Contributor Author

zerkms commented Oct 10, 2018

@bcoca documentation examples were inclusive, see the cron example, and the enumeration example.

If you did read the documentation exactly - you would implement your playbooks with that in mind.

"{{ 59 |random}} * * * * root /script/from/cron"

this example makes only sense if it was inclusive.

@bcoca
Copy link
Member

bcoca commented Oct 10, 2018

mostly, its still valid to not want minute 59 exactly, its 'implied' but not stated, that is why we updated them

@zerkms
Copy link
Contributor Author

zerkms commented Oct 10, 2018

@bcoca honestly, does it make any sense for you to provide an example that deliberately omits 59 and not mention it?

Before it was implied. Now it's stated explicitly but with different semantics, hence it's a BC.

But whatever, you develop this project.

Wondering how many people now need to change their playbooks (at least me).

@bcoca
Copy link
Member

bcoca commented Oct 10, 2018

That is not the point, the examples still work but not as implied, the problem with changing the code is that existing playbooks WILL break as the limit changes, while changing docs allows people to correct their usage of it willingly, not because a playbook now suddenly behaves differently.

I agree with you on what the problem was, the solution has to take into account NOT breaking existing playbooks, which the doc fix accomplishes but the behaviour change does not.

@zerkms
Copy link
Contributor Author

zerkms commented Oct 10, 2018

existing playbooks WILL break as the limit changes

that's not true: those who read the documentation exactly assumed the intervals are inclusive.

not because a playbook now suddenly behaves differently.

it does not: behaviour was implicitly set by the documentation

NOT breaking existing playbooks, which the doc fix accomplishes but the behaviour change does not.

it totally breaks now: people who relied on random values to be inclusive now must change it everywhere. What I literally will have to do is to grep everything for random and manually change. If I must change my code to comply with the new version it's a BC.

@bcoca
Copy link
Member

bcoca commented Oct 10, 2018

@zerkms sadly most people don't read the docs and just use the code with their own assumptions, which we have learnt in this project time and time again.

Changing the docs will clarify it for the people that actually do read them, but the people that were using the feature 'as it works' will not see their playbook's behaviour change. I don't disagree with you in principal, but given the choice i have to take the one the preserves current behaviour and make documentation match it vs the other way around.

@zerkms
Copy link
Contributor Author

zerkms commented Oct 10, 2018

Yep, I would gladly accept any solution, my apologies for heating up this discussion :-(.

@bcoca
Copy link
Member

bcoca commented Oct 10, 2018

@zerkms I understand and agree that your fix is 'more correct' but I have to look at it form the point of preserving existing behaviour unless it is clearly wrong. In this case it not really right or wrong to be inclusive/exclusive both work ... as long as we clearly state which one we use, so we are mostly forced to continue with behaviour and correct documentation, assumptions might need to be updated, but playbooks won't suddenly behave differently w/o users updating them.

bcoca added a commit to bcoca/ansible that referenced this pull request Dec 19, 2018
…lusive (ansible#27215)"

This reverts commit ea2b89c.

reverted fix as agreed at the time, but missed by maintainers.
@bcoca bcoca mentioned this pull request Dec 19, 2018
maxamillion pushed a commit that referenced this pull request Dec 19, 2018
* Revert "Fix incorrect examples with random filter (#50137)"

This reverts commit 9a7dbd5.

The correction is incomplete and also based on a 'fix' that was supposed to have been reverted already

* Revert "Added `+1` to the `end` in `random` filter so that it was inclusive (#27215)"

This reverts commit ea2b89c.

reverted fix as agreed at the time, but missed by maintainers.
kbreit pushed a commit to kbreit/ansible that referenced this pull request Jan 11, 2019
* Revert "Fix incorrect examples with random filter (ansible#50137)"

This reverts commit 9a7dbd5.

The correction is incomplete and also based on a 'fix' that was supposed to have been reverted already

* Revert "Added `+1` to the `end` in `random` filter so that it was inclusive (ansible#27215)"

This reverts commit ea2b89c.

reverted fix as agreed at the time, but missed by maintainers.
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bug This issue/PR relates to a bug. c:plugins/filter plugins/filter stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Random module documentation/implementation is incorrect about end
6 participants