Skip to content

Replace the focus filter list on set instead of extending it - #3728

Merged
nicolargo merged 1 commit into
nicolargo:developfrom
datrixlab:fix/focus-filter-command-line-precedence
Sep 10, 2026
Merged

nicolargo merged 1 commit into
nicolargo:developfrom
datrixlab:fix/focus-filter-command-line-precedence

Conversation

@datrixlab

Copy link
Copy Markdown
Contributor

Description

GlancesFilterList.filter appends to the existing list rather than replacing it, so
the property never describes the current filter — each assignment adds to whatever
was already there. Its sibling in the same file, GlancesFilter.filter, replaces.

That matters because both process_focus and export_process_filter are written
twice during a normal startup:

focus export
glances.conf plugins/processlist/__init__.py:254 plugins/processlist/__init__.py:250
command line processes.py:163 (set_args) standalone.py:71

The plugin loads the configuration file first, the command line is applied just
after, and is_filtered() ORs the accumulated list. So with

[processlist]
focus=.*firefox.*
glances --process-focus .*python.*

Glances focuses on firefox and python together. The command line can widen the
list set in glances.conf, but never narrow it — while docs/config.rst states:

User-specific options override system-wide options, and options given on
the command line overrides both.

Assigning the whole list restores that precedence: the configuration file is read
first, the command line replaces it. --process-focus a,b still yields both, since
that is one assignment.

Reproduced against develop before the change:

config focus=nginx      -> ['nginx']
--process-focus python  -> ['nginx', 'python']
is_filtered({'name': 'nginx'})  = True     <- command line could not narrow it

Resume

  • Bug fix: yes
  • New feature: no
  • Fixed tickets: none open that I could find

Tests

Added to test_020_filter in tests/test_core.py: assign twice, assert the second
assignment is the whole filter. Verified by reverting glances/filter.py alone — the
new assertions fail with ['.*firefox.*', '.*python.*'] != ['.*python.*'], and every
pre-existing assertion passes both with and without the change.

tests/test_core.py: 48 passed, 6 skipped. The process- and filter-related suites
(test_processes_cache, test_plugin_processcount, test_sort_missing_values,
test_program_aggregation, test_globals, test_glances_stats, test_lazy_views):
115 passed. ruff check clean; ruff format --check reports only a pre-existing
complaint at tests/test_core.py:422, which is present on an unmodified develop.

GlancesFilterList.filter appended to the existing list, so the property
never described the current filter: every assignment added to whatever was
already there. Its sibling in the same file, GlancesFilter.filter, replaces.

Both process_focus and export_process_filter are written twice in a normal
startup. The processlist plugin reads glances.conf when it loads
(plugins/processlist/__init__.py), and the command line is applied just
after -- set_args() for the focus filter, standalone.py for the export one.
Appending left both live, and is_filtered() ORs them, so

    focus=.*firefox.*         in glances.conf
    glances --process-focus .*python.*

focused on firefox and python together. The command line could widen the
list from the configuration file but never narrow it, while config.rst
states that "options given on the command line overrides both".

Assigning the whole list restores that precedence: the configuration file
is read first, the command line replaces it.
@nicolargo nicolargo added the bug label Sep 10, 2026
@nicolargo nicolargo added this to the Glances 4.5.7 milestone Sep 10, 2026
@nicolargo
nicolargo merged commit ddaa65c into nicolargo:develop Sep 10, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants