Skip to content

SchemaAnalyzer: ensure identical order of elements#128

Open
barsnick wants to merge 1 commit into
mainfrom
fix/order-of-generated-code
Open

SchemaAnalyzer: ensure identical order of elements#128
barsnick wants to merge 1 commit into
mainfrom
fix/order-of-generated-code

Conversation

@barsnick

Copy link
Copy Markdown
Contributor

xmlschema stores substitution groups as set[XsdElement] and iterates them directly. Those XsdElement instances are object-hashed, so PYTHONHASHSEED=0 does not stabilize their order. A harmless Python source change can alter object allocation/timing, which changes set iteration order, which then changes generated type/function/grammar order.

Describe your changes

The SchemaAnalyzer now sorts substitution-group elements before consuming them, using stable schema data: element qualified name plus type name.

Issue ticket number and link

Fixes #84.

Checklist before requesting a review

  • I have performed a self-review of my code
  • I have made corresponding changes to the documentation
  • I read the contribution documentation and made sure that my changes meet its requirements

xmlschema stores substitution groups as set[XsdElement] and iterates them
directly. Those XsdElement instances are object-hashed, so PYTHONHASHSEED=0
does not stabilize their order. A harmless Python source change can alter
object allocation/timing, which changes set iteration order, which then
changes generated type/function/grammar order.

The SchemaAnalyzer now sorts substitution-group elements before consuming
them, using stable schema data: element qualified name plus type name.

Fixes #84.

Signed-off-by: Moritz Barsnick <moritz.barsnick@chargebyte.com>
@barsnick barsnick requested a review from SebaLukas May 20, 2026 08:47
@barsnick barsnick requested a review from chausGit as a code owner May 20, 2026 08:47
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 15 complexity · 0 duplication

Metric Results
Complexity 15
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@SebaLukas SebaLukas self-assigned this May 20, 2026

@SebaLukas SebaLukas 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.

The changes looking good! I just haven't tested it 😅

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.

Order of generated code is arbitrary / random

2 participants