Fix: needs_schema_definitions_from_json triggers full rebuild on every incremental build#1711
Closed
vanhci wants to merge 1 commit into
Closed
Fix: needs_schema_definitions_from_json triggers full rebuild on every incremental build#1711vanhci wants to merge 1 commit into
vanhci wants to merge 1 commit into
Conversation
…utation In resolve_schemas_config(), schemas from needs_config.schema_definitions['schemas'] were passed directly to populate_field_type(), which mutates them in place by injecting 'type' fields. Since resolve_schemas_config is connected to 'env-before-read-docs' (which fires after Sphinx's config-inited checkpoint), the mutations persisted in the pickled config. On subsequent builds, Sphinx detected a difference between the fresh JSON-loaded config and the pickled mutated config, triggering a full rebuild every time. Fix: Use copy.deepcopy() on each schema before passing to populate_field_type(), so the original config remains unchanged and the pickled config matches the fresh load.
Member
|
Thanks for the PR. |
Member
|
Release is out! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Bug: When
needs_schema_definitions_from_jsonis set, every incrementalsphinx-buildrebuilds ALL documents because Sphinx detects a spurious[config changed ('needs_schema_definitions')].Root Cause:
resolve_schemas_configis connected toenv-before-read-docs, and viapopulate_field_typemutatesneeds_config.schema_definitions['schemas']in place — injecting"type": "string"/"object"etc. into every nested schema. This event fires AFTER Sphinx'sconfig-initedconfig-change checkpoint:config-inited—schemas.jsonloaded →{"const": "role"}{"const": "role"}env-before-read-docs→populate_field_typemutates in place →{"const": "role", "type": "string"}Next build: step 2 compares fresh JSON (
{"const": "role"}) vs pickled mutated config ({"const": "role", "type": "string"}) → mismatch → full rebuild → permanent loop.Fix: In
resolve_schemas_config, deep-copy each schema withcopy.deepcopy()before passing it topopulate_field_type(), so the original config remains unchanged and the pickled config matches the fresh load.Changes
sphinx_needs/schema/config_utils.pyimport copyat line 5, modifiedresolve_schemas_config()(around line 103) to passcopy.deepcopy(schema)instead ofschemadirectly topopulate_field_type()Testing
The fix was verified by understanding the mutation flow:
populate_field_typeinjectstypefields into schemas, and by deep-copying before mutation, the original pickled config remains identical across builds.Fixes #1711