Skip to content

Fix shared CompositePublisher template data binding - #297

Closed
pengpengyi92 wants to merge 1 commit into
Point72:mainfrom
pengpengyi92:fix/composite-publisher-template-isolation-20261114
Closed

pengpengyi92 wants to merge 1 commit into
Point72:mainfrom
pengpengyi92:fix/composite-publisher-template-isolation-20261114

Conversation

@pengpengyi92

Copy link
Copy Markdown
Contributor

Description

Fix data being overwritten when CompositePublisher reuses a configured
publisher instance. For example, a named GenericFilePublisher can appear in
field_publishers["a"] and in default_publishers for field b:

shared = GenericFilePublisher(name="custom_a", suffix=".txt")
publisher = CompositePublisher(
    name="batch",
    data={"a": "ALPHA", "b": "BETA"},
    field_publishers={"a": shared},
    default_publishers=[shared],
)
paths = publisher()

Currently, both files contain BETA. _get_publishers() stores the original
named field publisher, then default selection assigns BETA to that same
object before either file is written.

Make the existing shallow model_copy() before assigning each field's data,
for both explicit and default publishers. Named publishers are copied too.
Validation still happens through normal assignment on the copy, and existing
naming, fallback ordering and error handling are unchanged. Configured publisher
templates retain their original data/name/name parameters.

Three regression methods check real file contents for the shared-instance case,
named/unnamed template preservation, and typed default-publisher validation
fallback. No mocked file writer, extra dependency or deep-copy traversal.

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Refactor / code cleanup
  • CI / build configuration
  • Other (describe below)

Local Validation

Base: 83f2b0ac7128c08c92f2b6fd60f58723ac47635a.

python -m pytest ccflow/tests/publishers ccflow/tests/models/test_publisher.py -q -o addopts=
python -m ruff check ccflow/publishers/composite.py ccflow/tests/publishers/test_composite.py
python -m ruff format --check ccflow/publishers/composite.py ccflow/tests/publishers/test_composite.py
  • Native Linux CPython 3.12.14, Pydantic 2.14.3: 31 passed, 2 subtests passed.
    This includes existing recursive, root, error-aggregation, file and
    PublisherModel tests. It is not a complete repository/version matrix.
  • Same tests and dependencies with the original production file: pytest reports
    4 failed, 29 passed, counting the two failing named/unnamed subtests.
    There are three new regression methods, not four independent new methods.
  • Windows CPython 3.12.13: new selection 3 passed, 2 subtests passed.
  • The nine original composite tests fail Windows temporary-directory cleanup
    because they chdir into a directory before its context exits. All nine also
    fail on the completely untouched baseline. No unrelated cleanup fix or test
    assertion change is bundled here; the full selection was run on Linux.
  • Ruff 0.17.5 changed-file checks/format, compilation and git diff --check pass.

Boundary: isolate per-field publisher binding with shallow model copies.
This is not a deep clone of arbitrary nested resources, a thread-safety claim,
or a fix for deliberately identical output paths. Cloud/service integrations,
full make test/make lint and complete compatibility CI were not run locally.
Separate from the typed NumPy serialization work in #296.

Checklist

  • Full linting passes (make lint) - changed-file Ruff checks above pass
  • Full tests pass (make test) - scoped native results above
  • Regression tests added
  • Documentation updated - no new public API
  • Changelog / version bump - left to maintainers

Prepared with AI coding assistance. Reproduction, tests and stated checks were
run locally. DCO sign-off explicitly authorized for this contribution.

Signed-off-by: Pengyi Peng <pengpengyi92@users.noreply.github.com>
@codecov

codecov Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.86%. Comparing base (83f2b0a) to head (1963777).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #297      +/-   ##
==========================================
+ Coverage   93.85%   93.86%   +0.01%     
==========================================
  Files         205      205              
  Lines       22944    22975      +31     
  Branches     1511     1512       +1     
==========================================
+ Hits        21533    21565      +32     
  Misses       1120     1120              
+ Partials      291      290       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@timkpaine

Copy link
Copy Markdown
Member

Thanks for the PR, i've consolidated several open ones in #299

@timkpaine timkpaine closed this Nov 14, 2026
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