Repository navigation
Conversation
markramm
left a comment
There was a problem hiding this comment.
Review at 8a0933b (conductor, 2026-11-17)
Automated: an Opus reviewer read the diff cold (the resolver, its caller, the entry dataclasses and the existing tests), then read it against the groom on #1639; the conductor checked its findings against the code. Read-only: nothing was run. CI on this head had not finished when this was written.
Thank you for picking this up within the hour. The refusal is in the right place: the one resolver, after the plain-name check and before any value is read, so a dry run and a real write answer the same. It reuses the existing ValidationError, and format-spec spellings such as {_x:>3} are covered.
The change refuses more than the issue asks, and that is the blocking part.
Blocking
-
pyrite/schema/field_schema.py,resolve_filename: refuse only a private field of the entry, not every name that starts with_. The new branchif field_name.startswith("_"): raiseruns before the metadata lookup. That is option B in the groom, which it recommends against. Two things that work ondevstop working:- A kb.yaml type whose entries carry the author's own key
_owner: aliceand whose pattern is{_owner}-{slug}.md. On a kb.yaml-declared type, unknown frontmatter keys live inentry.metadata, anddevresolves the name from there (elif field_name in meta). With this change every new entry of that type is refused, and the message says{_owner}"is not a data field", although it is the author's own data. - A
_-prefixed name the entry does not have at all ({_custom_private}). Ondevthat returnsNone, the documented fallback to the default file name for an absent field. Here it raises.
What the groom asks for (option A): refuse when the name starts with
_and is in{f.name for f in dataclasses.fields(entry)}. Leave_metadata keys resolving and absent_names falling back, as every other name does. With that condition, theif not f.name.startswith("_")filter you added todata_fieldsis no longer needed: keep one of the two, not both. - A kb.yaml type whose entries carry the author's own key
-
tests/test_file_pattern.py: the structural test from the groom's acceptance. The current test loops over four hand-written names onADREntry; the first failure hides the rest, and_importance_givenand_custom_privateare not fields ondev, so they only exercise the any-_rule. Wanted:- parametrise over
Entryand every class reachable by recursingEntry.__subclasses__()(import the model modules first soGenericEntryand the task entry are loaded), crossed with[f.name for f in dataclasses.fields(cls) if f.name.startswith("_")]; for each pair assertTypeSchema(name="t", file_pattern="{" + name + "}.md").resolve_filename(instance)raisesValidationError; - a guard that the collected list is not empty;
- controls: a public field still resolves; a metadata key
_drafton a kb.yaml-declared type still resolves; an absent_name still returnsNone;{date}--{slug}.mdis unchanged.
A new private field on any entry class is then refused without anyone editing the test. This also pins the groom's extra finding,
_entry_typeonGenericEntry, which no test builds today. - parametrise over
-
A changelog fragment. "Changelog: none" does not fit: a write now refuses a pattern it used to accept. Add
changelog.d/1639-<slug>.fixed.md, one line, saying what is refused and that_-prefixed metadata keys still resolve.
Non-blocking
- The message could say "names a private field of the entry" for this branch, so it reads differently from the method/property refusal.
- One test through
KBService.create_entry(or the CLI) would show the refusal reaches a caller asVALIDATION_FAILED. - #1633 adds
_importance_given; with the structural test nothing here needs to wait for it.
For the record: this change is under pyrite/schema/ and changes what a write accepts, so after the next head it is read cold again and the maintainer merges it. No rebase is needed; the merge queue accepts a branch that is behind.
Recommendation: request changes.
|
Thank you for the thorough and clear review! All three blocking points (and the non-blocking suggestions) have been addressed in commit
|
markramm
left a comment
There was a problem hiding this comment.
Review at 4b92cff (conductor, 2026-11-17)
Automated: an Opus reviewer read 83998ee cold and then against the three items of the last review; the conductor checked its findings in the diff. Read-only: nothing was run. The test legs on this head had not finished when this was written, so this review does not claim the gate. The head moved to 4b92cff while it was being read: that is 83998ee plus a merge of dev, and its three changed files are byte-for-byte the same (git diff --quiet), so the review stands for this head.
Thank you for the fast turn. All three blocking items are met:
- Option A: met.
TypeSchema.resolve_filenamerefusesfield_name in private_fields, built fromdataclasses.fields(entry)on the instance, so a subclass's own private fields (_entry_typeonGenericEntry) are covered with no list of names in production code. A_metadata key that is not a field still resolves, and an absent_name still returnsNone. Format-spec spellings ({_x:>3},{_x!r}) reach the refusal. - Structural test: met. Pairs are computed at collection from the class tree, with the non-empty guard; by reading, every cell resolves or returns
Noneondev, so each fails without the change. The four controls are real controls. The old loop test that was removed asserted the over-broad rule; nothing is weakened. - Fragment: met, and each claim in it matches the code. Both non-blocking suggestions (the message, the
KBService.create_entrytest) were taken too.
One change asked for, in tests/test_file_pattern.py, _collect_entry_private_field_pairs:
Entry.__subclasses__()also returnsEntrysubclasses that other test files define at module level (today: the probe classes intests/test_declared_type_mapping.pyand the classes intests/test_field_aliases.py). So this test's parameter list depends on which test files were collected before it: it differs between a full run and running this file alone, and a test-only class that_build_test_entrycannot build would fail here, in a file its author never touched. Please keep only production classes, for exampleif not cls.__module__.startswith(("pyrite.", "pyrite_")): continue.- Sort by
(c.__module__, c.__qualname__)instead ofc.__name__. With names alone, two classes of the same name sort in set order, which differs between pytest-xdist workers and stops the run with "different tests were collected".
Optional, same push: data_fields still filters out _ names, but the refusal runs first, so data_fields = dataclass_fields - private_fields says the same with one filter.
For the record: this change is under pyrite/schema/ and changes what a write accepts, so the maintainer merges it. A merge of dev is not needed while the PR is mergeable; the merge queue accepts a branch that is behind.
Recommendation: merge after this one change.
|
Thank you for the review! Addressed in commit
|
markramm
left a comment
There was a problem hiding this comment.
Review at 7373d0c (conductor, 2026-11-17)
Automated: read by the conductor from the pushed head (the change since 4b92cff: one commit, two files). Nothing was run. The checks on this head had not started when this was written, so this review does not claim the gate.
The one change asked for is made as asked: _collect_entry_private_field_pairs keeps only classes whose module starts with pyrite. or pyrite_, sorts by (module, qualname), and the ids use the qualname. Entry itself (pyrite.models.base) is still in the list. The optional tidy is in too: data_fields = dataclass_fields - private_fields, one filter, same sets.
Nothing else changed since the last review, so its three "met" items stand. Nothing further is needed from you. Thank you for three fast, exact rounds.
For the maintainer: this is under pyrite/schema/ and changes what a write accepts (a file_pattern naming a private entry field is refused with VALIDATION_FAILED), so the merge is yours once the gate is green on this head. The Opus read of the previous head found no blocking item; fragment present; #1639 is in 0.26.5.
Recommendation: merge.
Summary
Fixes #1639.
In
FieldSchema.resolve_filename(pyrite/schema/field_schema.py):dataclass_fieldsand split intodata_fieldsandprivate_fields(f.name.startswith("_")).field_name in private_fields, raisingValidationError(f"file_pattern {self.file_pattern!r} names {{{field_name}}}, which is a private field of entry {entry.id!r} (type {entry.entry_type!r}); refusing to resolve it")._(e.g._owner,_drafton kb.yaml-declared types) continue to resolve fromentry.metadata, and absent_-prefixed names fall back to default filename (None).Entryand all subclasses reachable viaEntry.__subclasses__()crossed with each class's_-prefixed dataclass fields (143 pairs), asserting refusal. Added four control tests (public fields resolve,_draftmetadata key on generic entry resolves, absent_name returnsNone, and{date}--{slug}.mdunchanged) and a test throughKBService.create_entry.changelog.d/1639-file-pattern-private-fields.fixed.md.Changelog: added