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

Refactor the FIELD pseudo-cause into the catch-all events and a field filter #69

Merged
merged 1 commit into from
May 28, 2019

Conversation

nolar
Copy link
Contributor

@nolar nolar commented May 22, 2019

Issue : #13

The FIELD pseudo-cause was introduced as an easy way to mark the per-field handlers (@kopf.on.field), and then to select them on the event handling. The field handlers were handled separately, after all the object handlers.

Over time, this pseudo-cause was merged into the overall handling routine, and has become a problem: it prevents further refactoring (of event/cause detection and handling), which in turn is needed for the test coverage.


This PR is a set of changes extracted from a bigger branch for the ease of code review (one small part at a time). It does NOT change the behaviour of the framework or of any handlers; it just changes the internal implementation of it:

  • No more FIELD pseudo-causes in the code.
  • The catch-all handlers (event==None) with field property set are now used — i.e. any event as long as this field is in the diff. Efficiently, it means only the UPDATE events — same as before.

In addition, the tests of handler selection were improved to reflect all cases; and to make the test ids more readable.

@nolar nolar added the automation CI/CD: testing, linting, releasing automatically label May 22, 2019
@nolar nolar added this to the 1.0 milestone May 22, 2019
@nolar nolar requested a review from samurang87 as a code owner May 22, 2019 14:12
@zincr
Copy link

zincr bot commented May 22, 2019

🤖 zincr found 0 problems , 1 warning

ℹ️ Large Commits
✅ Approvals
✅ Specification
✅ Dependency Licensing

Details on how to resolve are provided below


Large Commits

Checks all commits for large additions to a single file. Large commits should be reviewed more carefully for potential copyright and licensing issues

This file contains a substantial change, please review to determine if the change comes from an external source and if there are any copyright or licensing issues to be aware of

@zincr
Copy link

zincr bot commented May 22, 2019

🤖 zincr found 1 problem , 1 warning

❌ Approvals
ℹ️ Large Commits
✅ Specification
✅ Dependency Licensing

Details on how to resolve are provided below


Approvals

All proposed changes must be reviewed by project maintainers before they can be merged

Not enough people have approved this pull request - please ensure that 1 additional user, who have not contributed to this pull request approve the changes.

  • ✅ Approved by PR author @nolar
  • ❌ 1 additional approval needed
     

Large Commits

Checks all commits for large additions to a single file. Large commits should be reviewed more carefully for potential copyright and licensing issues

This file contains a substantial change, please review to determine if the change comes from an external source and if there are any copyright or licensing issues to be aware of

@nolar nolar changed the title Refactor FIELD pseudo-cause into the catch-all events and a field filter Refactor the FIELD pseudo-cause into the catch-all events and a field filter May 23, 2019
@nolar nolar force-pushed the no-field-pseudo-cause branch from 59aa73d to be7e701 Compare May 28, 2019 09:33


@pytest.fixture()
@pytest.fixture(params=[
pytest.param([('op', ('some-field',), 'old', 'new')], id='with-field-diff'),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does 'op' mean here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Operation. Usually it is one of: add, change, remove. In this case, it is irrelevant, as the object-under-test is the cause & handlers, not the diff — but a list of 4-item tuples is expected in the internal for-cycle, no matter what's inside, so we give it.

def test_catchall_handlers_with_field_found(cause_with_diff, registry, register_fn):
register_fn(some_fn, event=None, field='some-field')
handlers = registry.get_handlers(cause_with_diff)
assert handlers

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you assert when this is not empty? Does it mean it catches all the handlers?

Copy link
Contributor Author

@nolar nolar May 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. It means, that something is there, i.e. non-empty.

There is only one handler registered in the previous line, so technically it also means that all handlers are returned (for that field: since both then handler and the cause contain this field — in this specific test).

@nolar nolar merged commit c1e323d into zalando-incubator:master May 28, 2019
@nolar nolar deleted the no-field-pseudo-cause branch May 28, 2019 15:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
automation CI/CD: testing, linting, releasing automatically
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants