Skip to content

Fix unordered collection handling and project accessor patterns#178

Merged
MattGyverLee merged 4 commits into
mainfrom
claude/vigilant-pasteur-lZOBI
May 30, 2026
Merged

Fix unordered collection handling and project accessor patterns#178
MattGyverLee merged 4 commits into
mainfrom
claude/vigilant-pasteur-lZOBI

Conversation

@MattGyverLee
Copy link
Copy Markdown
Owner

Summary

This PR corrects two systematic issues across the codebase:

  1. Unordered Collection (OC) Handling: Several Duplicate() methods were incorrectly attempting to insert duplicated objects at specific positions within unordered collections. Since OC collections don't support positional insertion, the insert_after parameter is a no-op for these collections and objects should always be added at the end.

  2. Project Accessor Pattern: Updated property access patterns to use the canonical Cache.LanguageProject accessor instead of the indirect OwnerOfClass.project pattern, which is more reliable and follows LCM best practices.

Key Changes

Unordered Collection Fixes

  • DiscourseOperations.py: Simplified ChartsOC insertion logic to always use Add() instead of conditionally using Insert()
  • WfiAnalysisOperations.py: Simplified AnalysesOC insertion logic to always use Add()
  • WfiGlossOperations.py: Simplified MeaningsOC insertion logic to always use Add()
  • GramCatOperations.py: Simplified TypesOC insertion logic to always use Add()
  • DataNotebookOperations.py: Simplified RecordsOC insertion logic to always use Add()
  • NoteOperations.py: Simplified AnnotationsOC insertion logic to always use Add()

Project Accessor Updates

  • allomorph.py: Changed three instances from self._obj.OwnerOfClass.project to self._obj.Cache.DefaultVernWs and self._obj.Cache.DefaultAnalWs for direct writing system access
  • lcm_casting.py: Updated clone_properties() to resolve project via dest.Cache.LanguageProject instead of dest.OwnerOfClass.project

Implementation Details

  • All OC collection insertions now include explanatory comments noting that OC is unordered and insert_after is a no-op
  • The insert_after parameter remains in method signatures for API compatibility but is effectively ignored for unordered collections
  • Cache-based accessors provide more direct and reliable access to language project and writing system information

https://claude.ai/code/session_01WsYz9YzNkyFzkStEr1y8Fg

claude and others added 4 commits May 30, 2026 19:09
…DefaultXxxWs (#147)

Three sites in allomorph.py used self._obj.OwnerOfClass.project.DefaultVernWs /
DefaultAnalWs. OwnerOfClass is an LCM method (requires an Int32 class-id arg);
bare attribute access returns the bound method object, so .project raises
AttributeError, silently swallowed by the bare except — making every property
return "". Fixed by using self._obj.Cache.DefaultVernWs / DefaultAnalWs instead,
matching the pattern used by the May-20 sweep in phonological_rule.py et al.

Closes #147

https://claude.ai/code/session_01WsYz9YzNkyFzkStEr1y8Fg
…stead of OwnerOfClass.project (#153)

clone_properties() tried to resolve project via dest.OwnerOfClass.project.
OwnerOfClass is an LCM method (requires an Int32 class-id arg); accessing it
as a bare attribute returns the bound method object, not an ICmObject, so
.project raises AttributeError -- silently swallowed by the bare except.
This left `project = None`, permanently killing the collection-clone branch
at line 511 (if project:) for every caller that didn't pass project explicitly.

Fix: use dest.Cache.LanguageProject, the canonical accessor used elsewhere
in the codebase since commit 611f5a3.

Closes #153

https://claude.ai/code/session_01WsYz9YzNkyFzkStEr1y8Fg
… support positional ops (#167)

LcmOwningCollection (OC suffix) implements ICollection, not IList. Calling
IndexOf or Insert on it either silently no-ops or raises in pythonnet,
so insert_after=True on OC-backed Duplicate methods never worked. For the
two half-fixed sites (WfiGloss, WfiAnalysis) the list(...).index() workaround
avoided the IndexOf failure but the follow-up .Insert() was still broken.

Fix: replace the entire insert_after branch with an unconditional .Add() on
the six affected OC collections:
  - NoteOperations.py:    AnnotationsOC
  - DataNotebookOperations.py: RecordsOC
  - GramCatOperations.py: TypesOC
  - DiscourseOperations.py: ChartsOC
  - WfiGlossOperations.py: MeaningsOC
  - WfiAnalysisOperations.py: AnalysesOC

OS-backed collections (SubRecordsOS, RepliesOS, SubPossibilitiesOS) are
unaffected -- positional Insert is well-defined there.

Closes #167

https://claude.ai/code/session_01WsYz9YzNkyFzkStEr1y8Fg
@MattGyverLee MattGyverLee merged commit 679ee13 into main May 30, 2026
0 of 3 checks passed
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