Skip to content

Preserve user-supplied ConsumerConfig.filter_subject on subscribe - #990

Draft
caspervonb wants to merge 2 commits into
mainfrom
fix-501
Draft

Preserve user-supplied ConsumerConfig.filter_subject on subscribe#990
caspervonb wants to merge 2 commits into
mainfrom
fix-501

Conversation

@caspervonb

Copy link
Copy Markdown
Collaborator

The auto-create path guarded on filter_subjects (plural) but assigned filter_subject (singular), so a config that set only the singular field had it silently overwritten with the subscribe subject.

Fixes #501.

The auto-create path guarded on filter_subjects (plural) but then
assigned filter_subject (singular), so a consumer config that set only
the singular filter_subject had it silently overwritten with the
subscribe subject. Guard on both before defaulting.
@caspervonb caspervonb added the nats-legacy Legacy asyncio NATS client label Jul 14, 2026
@synadia-claude-reviewer

synadia-claude-reviewer Bot commented Jul 14, 2026

Copy link
Copy Markdown

Claude finished @caspervonb's task in 1m 24s —— View job


PR Review

  • Gather PR diff and context
  • Review changed files
  • Post findings

The fix is correct and well-targeted. The push-subscribe auto-create path checked filter_subjects (plural) before assigning filter_subject (singular), so a user-supplied singular filter was silently clobbered. Adding and not config.filter_subject to the guard is the minimal, right fix.

One issue found: the same bug exists in pull_subscribe() at nats/src/nats/js/client.py:599, which this PR does not address:

# nats/src/nats/js/client.py  ~line 598-600
# Auto created consumers use the filter subject, unless filter_subjects is set.
if not config.filter_subjects:          # ← same bug: ignores user-supplied filter_subject
    config.filter_subject = subject

This should receive the identical fix: if not config.filter_subjects and not config.filter_subject:. A companion regression test for pull_subscribe would be worth adding too.

Test (nats/tests/test_js.py): the regression test is clear and sufficient for the push case. Minor note — sub is not drained or unsubscribed before nc.close(), but looking at surrounding tests that pattern is consistent with the rest of the suite so it's fine.

The pull_subscribe auto-created consumer guard only checked
filter_subjects, so a user-supplied singular filter_subject on the
ConsumerConfig was clobbered with the subscribe subject. Mirror the
guard used on the push subscribe path so both filters are honored.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

nats-legacy Legacy asyncio NATS client

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: NatsJS subscribe rewrites original ConsumerConfig(filter_sibject=...) option

1 participant