Skip to content

etas: keep the filters passed to the constructor - #2167

Merged
zariiii9003 merged 6 commits into
hardbyte:mainfrom
bIackr0se:fix/etas-constructor-filters
Nov 29, 2026
Merged

zariiii9003 merged 6 commits into
hardbyte:mainfrom
bIackr0se:fix/etas-constructor-filters

Conversation

@bIackr0se

Copy link
Copy Markdown
Contributor

Summary of Changes

can.Bus(interface="etas", channel=..., can_filters=[...]) ends up with an accept-all frame filter (can_id 0, can_mask 0) on its receive queue, so the receive queue applies no CAN ID restriction and the requested identifier filters have no effect. Opening the bus without filters and calling bus.set_filters(...) afterwards is not affected.

In can/interfaces/etas/__init__.py, EtasBus.__init__ installs the filters with self.filters = can_filters. The BusABC.filters setter calls set_filters, which calls EtasBus._apply_filters. At the end of the constructor, EtasBus.__init__ calls super().__init__(channel=channel, **kwargs) without can_filters. Because can_filters is a named parameter of EtasBus.__init__, it is not in kwargs. BusABC.__init__ therefore calls self.set_filters(None). EtasBus._apply_filters then calls OCI_RemoveCANFrameFilterEx on the installed filters and OCI_AddCANFrameFilterEx with an accept-all filter (can_id 0, can_mask 0).

PR #1704 ("Fix initialization order in EtasBus") moved super().__init__() to the end of the constructor because super calls set_filters. Before that change, the base call ran first. After it, the base call's set_filters(None) runs after the constructor installs can_filters.

This change removes self.filters = can_filters and calls super().__init__(channel=channel, can_filters=can_filters, **kwargs). BusABC.__init__ then installs the requested filters once at that point in initialization. self._oci_filters = None stays before the base call, so the first _apply_filters call removes nothing. Without can_filters, the bus installs the same accept-all filter as before.

Calling can.Bus(interface="etas", ...) with requested filters 0x123/0x7FF and 0x456/0x7FF against a stub replacing the BOA libraries (dll-csiBind, dll-ocdProxy) records these frame filter calls:

# main
OCI_AddCANFrameFilterEx    [('0x123', '0x7ff'), ('0x456', '0x7ff')]
OCI_RemoveCANFrameFilterEx [('0x123', '0x7ff')]
OCI_AddCANFrameFilterEx    [('0x0', '0x0')]
filters on the receive queue: [('0x456', '0x7ff'), ('0x0', '0x0')]

# this branch
OCI_AddCANFrameFilterEx    [('0x123', '0x7ff'), ('0x456', '0x7ff')]
filters on the receive queue: [('0x123', '0x7ff'), ('0x456', '0x7ff')]

A new test module, test/test_etas.py, loads can.interfaces.etas with ctypes.windll patched to a stub library using the patch.object(ctypes, "windll", ..., create=True) approach from test/test_pcan.py. It runs without the ETAS BOA install and tracks which frame filters are installed on the receive queue. test_constructor_filters_are_installed checks frame ID, mask and flag values for a filter without the extended key and for an extended filter. That test fails on main and passes with the fix. test_no_constructor_filters_accepts_all and test_set_filters_replaces_constructor_filters pass on both branches and guard the unchanged paths. The orphan news fragment doc/changelog.d/+etas-constructor-filters.fixed.rst records the fix.

Related Issues / Pull Requests

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Refactoring
  • Other (please describe):

Checklist

  • I have followed the contribution guide.
  • I have added or updated tests as appropriate.
  • I have added or updated documentation as appropriate.
  • I have added a news fragment for towncrier.
  • All checks and tests pass (tox).

Additional Notes

Behavior is checked at the OCI call boundary without ETAS hardware. The count of 1 in the main removal call is a separate issue left for its own change (a later set_filters() after a bus opened with several filters leaves all but the first old filter installed). The same holds for a filter with "extended": False, which _apply_filters installs without constraining the extended flag; the new tests do not depend on that.

@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-29T20:08:30.569835Z
We couldn’t complete this review. Comment @codex review to try again.
7aebc0b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@zariiii9003 zariiii9003 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you

@zariiii9003
zariiii9003 merged commit 464304e into hardbyte:main Nov 29, 2026
26 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants