Skip to content

fix(config): align additional_properties typing - #5286

Open
hariharan077 wants to merge 4 commits into
open-telemetry:mainfrom
hariharan077:fix-config-additional-properties-typing
Open

hariharan077 wants to merge 4 commits into
open-telemetry:mainfrom
hariharan077:fix-config-additional-properties-typing

Conversation

@hariharan077

@hariharan077 hariharan077 commented Jun 10, 2026 •

Copy link
Copy Markdown

Description

Fixes #5268.

Declare generated config model additional_properties attributes as instance dataclass fields instead of ClassVars, matching the runtime behavior of @_additional_properties and the _ComponentConfig protocol.

This also skips non-init dataclass fields while resolving configured resource detectors and converting dictionaries to dataclasses, so the generated additional_properties field is not treated as a configured component name or constructor argument.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Reproduced the strict pyright failure locally with a temporary SpanExporter/_resolve_component repro before the fix
  • uv run tox -e generate-config-from-jsonschema
  • uv run tox -r -e py310-test-opentelemetry-configuration (381 passed, 29 subtests passed)
  • uv run tox -r -e lint-opentelemetry-configuration (Pylint 10.00/10)
  • uv run ruff check opentelemetry-configuration
  • uv run ruff format --check opentelemetry-configuration
  • uv run towncrier build --draft --version Unreleased
  • git diff --check

Does This PR Require a Contrib Repo Change?

  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

Changelog and codegen README documentation are included for the additional_properties field design.

Compatibility review — pending

At 558bf4b, the public-symbols check reports 13 generated additional_properties attribute-value changes. Reproduced with Griffe 1.15.0 against 74544f0. Constructor signatures and runtime extras are unchanged, but the conversion from annotation-only ClassVars to dataclass fields changes equality, repr, and dataclass serialization/introspection. This should not be treated as confirmed non-breaking until maintainers decide whether those changes are intended. No compatibility exemption has been added.

Detailed comparison and maintainer question.

AI assistance: Codex performed the compatibility comparison; human compatibility approval remains pending.

@hariharan077
hariharan077 requested a review from a team as a code owner June 10, 2026 17:13
@hariharan077
hariharan077 force-pushed the fix-config-additional-properties-typing branch from 6b20701 to 8eb46b0 Compare June 10, 2026 17:14

@MikeGoldsmith MikeGoldsmith left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @hariharan077 - sorry for the slow review.

There's a couple of things that need fixing:

  • We're still importing typing.ClassVar - I think we should be using dataclasses.field instead
  • The README.md needs updating with the new design, the field is now an init=False dataclass field with default_factory=dict and the @_additional_properties decorator assigns the extras in the constructor
  • You need to add a changelog fragment, something like .changelog/5286.fixed

@github-project-automation github-project-automation Bot moved this to Reviewed PRs that need fixes in Python PR digest Jun 24, 2026
@MikeGoldsmith MikeGoldsmith self-assigned this Jun 24, 2026
@MikeGoldsmith MikeGoldsmith added the config Issues and PRs related to implementing Declarative Config label Jun 24, 2026
@hariharan077

Copy link
Copy Markdown
Author

Addressed the review comments in ebb349e: updated the codegen README for the init=False/default_factory additional_properties field, added .changelog/5286.fixed, and refreshed the PR checklist. Local focused tests, SDK lint, ruff, and towncrier draft all pass.

@hariharan077

Copy link
Copy Markdown
Author

Rebased the PR onto current main and pushed cf5c4f2. This carries the additional_properties field change over the v1.1 schema update and keeps conversion/resource handling aligned with non-init dataclass fields.

@github-actions

Copy link
Copy Markdown

This PR has been automatically marked as stale because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 days of this comment.
If you're still working on this, please add a comment or push new commits.

@github-actions github-actions Bot added the Stale label Jul 11, 2026
@MikeGoldsmith

Copy link
Copy Markdown
Member

Hi @hariharan077 - I'm sorry but this PR has been affected by another PR which moved a lot of the config into a new package.

Please can you update your PR to use the new paths.

@hariharan077
hariharan077 force-pushed the fix-config-additional-properties-typing branch from cf5c4f2 to 859abf5 Compare July 13, 2026 13:56
@github-actions github-actions Bot removed the Stale label Jul 14, 2026
@github-actions

Copy link
Copy Markdown

This PR has been automatically marked as stale because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 days of this comment.
If you're still working on this, please add a comment or push new commits.

@github-actions github-actions Bot added the Stale label Jul 28, 2026
@hariharan077
hariharan077 force-pushed the fix-config-additional-properties-typing branch from 859abf5 to f7592ff Compare August 2, 2026 09:39
@github-actions github-actions Bot removed the Stale label Aug 3, 2026
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Aug 14, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Waiting on the author · refreshed 2026-10-22 17:41 UTC

Investigate required status check failures.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Should this be with reviewers? Comment /dashboard route:reviewers to route it to them.
  • Anything wrong — including the routing? Report it with what you expected; it helps us improve the dashboard.

@opentelemetry-pr-dashboard

This comment has been minimized.

Reapply the additional_properties dataclass-field change on top of the v1.1 declarative configuration schema update and keep conversion helpers from treating non-init fields as constructor kwargs.

Assisted-by: GPT-5 Codex
@hariharan077
hariharan077 force-pushed the fix-config-additional-properties-typing branch from f7592ff to c695304 Compare August 21, 2026 18:30

Copy link
Copy Markdown
Author

@MikeGoldsmith The path update requested after #5356 is included in c695304. The codegen template, generated models, conversion/resource handling, and tests now use the opentelemetry-configuration/ package paths. The codegen README and .changelog/5286.fixed are also included.

Could you please take another look? The CI, changelog, and check-links workflows currently report action_required; could a maintainer check whether they need approval to run?

@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown

This PR has been automatically marked as stale because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 days of this comment.
If you're still working on this, please add a comment or push new commits.

@github-actions github-actions Bot added the Stale label Oct 2, 2026

Copy link
Copy Markdown
Author

@MikeGoldsmith The package-path changes requested after #5356 are included, along with the codegen README and changelog. Could you please take another look and let me know if anything else is needed?

@github-actions github-actions Bot removed the Stale label Oct 3, 2026
@github-project-automation github-project-automation Bot moved this from Reviewed PRs that need fixes to Approved PRs in Python PR digest Oct 16, 2026
@xrmx
xrmx requested a balanced review from Copilot October 22, 2026 07:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The generated root configuration annotation excludes schema-valid scalar and array extras, undermining the intended typing correction.

1 open issue
What changed in this PR

This PR addresses #5268 by aligning generated configuration model fields with the decorator’s runtime behavior and the component protocol.

Changes:

  • Replaces ClassVar annotations with non-init instance dataclass fields.
  • Skips non-init fields during dictionary conversion and resource detector resolution.
  • Updates regression checks, code generation documentation, and the changelog.
File Description
pyproject.toml Imports dataclasses.field for code generation.
opentelemetry-configuration/​tests/​test_conversion.py Updates the conversion fixture to use an instance field.
opentelemetry-configuration/​tests/​test_common.py Checks field metadata and instance isolation.
opentelemetry-configuration/​src/​opentelemetry/​configuration/​models.py Regenerates additional-properties instance fields.
opentelemetry-configuration/​src/​opentelemetry/​configuration/​_resource.py Excludes non-init fields from detector resolution.
opentelemetry-configuration/​src/​opentelemetry/​configuration/​_conversion.py Excludes non-init fields from constructor-field conversion.
opentelemetry-configuration/​src/​opentelemetry/​configuration/​_common.py Updates decorator field filtering and protocol documentation.
opentelemetry-configuration/​codegen/​README.md Documents the instance-field design.
opentelemetry-configuration/​codegen/​dataclass.jinja2 Generates typed non-init fields instead of class variables.
.changelog/​5286.fixed Records the configuration typing fix.

Review effort: Balanced

Comment thread opentelemetry-configuration/codegen/dataclass.jinja2
Keep root configuration extras typed as Any while preserving object-or-null component extras. Regenerate models and cover annotations, constructor extras, and dictionary conversion.

Assisted-by: Codex
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-22T09:04:46.829725Z 1064cc6 New commits
ℹ️ 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.

Copy link
Copy Markdown
Author

The additional-properties review item is fixed in 1064cc6, with regression coverage and 422 configuration tests plus 29 subtests passing locally. The inline thread is resolved.

The new CI, changelog, check-links, and Zizmor runs report action_required. Could a maintainer approve the workflows to run and take another look at the update?

AI assistance: Codex implemented and locally validated this follow-up.

@lzchen
lzchen enabled auto-merge October 22, 2026 15:56

Copy link
Copy Markdown
Author

Compatibility review for the current head 558bf4b against main 74544f0:

I reproduced public-symbols-check locally with Griffe 1.15.0 and the same comparison base. It exits 1 with the same 13 additional_properties attribute-value findings: failing CI job.

Griffe's None -> field(default_factory=dict, init=False) output needs a distinction: the old source declares an annotation-only ClassVar, with no assigned default. It does not give instances a runtime default of None. In an isolated comparison using the actual generated models and decorator from both revisions, all 13 models retain the same constructor signature, independent empty instance dictionaries, and preservation of supplied extras. Class-level attribute access raises AttributeError in both revisions.

However, making these real dataclass fields does change public behavior across all 13 models:

  • Instances with different extras compare equal on main, but unequal in this PR.
  • Extras now appear in generated repr().
  • dataclasses.asdict(), astuple(), and fields() now include the additional-properties field.

So the failure should not be dismissed as only a static-analysis false positive. The existing tests do not establish backwards compatibility for those behaviors. The package is documented as experimental, but whether to accept this change still needs a maintainer decision.

@MikeGoldsmith, does the previously requested init=False/default_factory=dict design intend these equality/representation/serialization changes, or should the implementation preserve the previous behavior? If they are intentional, the changelog should describe them and the compatibility-check treatment should be explicitly agreed and narrowly scoped. I have not added an exemption or requested a rerun.

The earlier README, package-path, and changelog requests are present in the current diff. This compatibility decision is still open.

AI assistance: Codex reproduced the checker and performed the model-level comparison; this is not human compatibility approval.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

config Issues and PRs related to implementing Declarative Config

Projects

Status: Approved PRs

Development

Successfully merging this pull request may close these issues.

refactor(config): review additional_properties typing for stricter type checks

4 participants