Fix non-deterministic collection order for module-scanned injectables - #147
Open
afonsojanu wants to merge 1 commit into
Open
Fix non-deterministic collection order for module-scanned injectables#147afonsojanu wants to merge 1 commit into
afonsojanu wants to merge 1 commit into
Conversation
_find_objects_in_module collected discovered classes into a set, so Sequence[T]/Mapping[T] ordering was hash-order (id()-derived) rather than the documented registration order whenever injectables came from a scanned module instead of an explicit list. Directory walks also relied on Path.iterdir(), which isn't guaranteed stable. Switch discovery to an insertion-ordered dict-as-set and sort the directory walk, so scanned modules produce deterministic results. Fixes maldoinc#144
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.
Fixes #144
_find_objects_in_modulecollected discovered classes into aset, soSequence[T]/Mapping[T]ordering followed hash order (id()-derived) rather than the documented registration order whenever injectables came from a scanned module instead of an explicit list — matches the reproduction in the issue.This switches discovery to an insertion-ordered
dict-as-set (order comes frominspect.getmembers, already sorted by name) and sorts the directory walk (path.iterdir()isn't guaranteed stable), so module-scanned discovery is deterministic across runs.Added a regression test with a module scanning 4 out-of-order qualified implementations, confirmed it fails on
masterand passes here.