Skip to content
This repository has been archived by the owner on Sep 14, 2020. It is now read-only.

Fix on-field handler selection when a field is longer/equal to a diff #340

Merged
merged 1 commit into from
Apr 6, 2020

Conversation

nolar
Copy link
Contributor

@nolar nolar commented Apr 2, 2020

What do these changes do?

Fix an issue with not calling the field-handlers if the change is too big/generic (regression).

Description

This issue was once fixed in #191. Since then, the handler selection was moved to other functions and places, and that logic was not reproduced.

The issue happens when there is a handler for a field, and a diff is too big and generic, not specific to sub-fields. For example:

import kopf

@kopf.on.field(..., field='metadata.labels')
def propagate_labels(diff, **_):
    pass

And the diff is:

[('add', ('metadata', 'labels'), None, {'x': 'y'}))]

This can happen when the labels are added to an object which previously had no labels. If it had any other labels, it is all fine, since the diff becomes specific only to the new labels:

[('add', ('metadata', 'labels', 'x'), None, 'y'))]

This PR fixes that issue for on-field handler selection. The same or similar-purpose code already exists in kopf.structs.diffs.reduce_iter().

Issues/PRs

Issues: #190

Related: regression of #191

Type of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • The code addresses only the mentioned problem, and this problem only
  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt

@zincr
Copy link

zincr bot commented Apr 2, 2020

🤖 zincr found 0 problems , 0 warnings

✅ Large Commits
✅ Approvals
✅ Specification
✅ Dependency Licensing

@nolar nolar added the bug Something isn't working label Apr 2, 2020
@nolar nolar requested a review from mnarodovitch April 3, 2020 08:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants