Repository navigation
fix: give CompiledSearchTerm a None related_terms default - #354
Open
Kevin Turcios (KRRT7) wants to merge 1 commit into
Open
Kevin Turcios (KRRT7) wants to merge 1 commit into
Kevin Turcios (KRRT7) wants to merge 1 commit into
Conversation
CompiledSearchTerm was a stdlib dataclass subclassing the pydantic
dataclass SearchTerm, so it took SearchTerm's pydantic Field object as the
default of related_terms instead of None. CompiledSearchTerm(Term("x"))
therefore had a truthy, non-list related_terms, which crashed
dedupe_related_terms. Declare it with the same pydantic dataclass
decorator as SearchTerm.
Co-authored-by: wtfyd-agent[bot] <328989958+wtfyd-agent[bot]@users.noreply.github.com>
Bernhard Merkle (bmerkle)
approved these changes
Oct 18, 2026
Bernhard Merkle (bmerkle)
left a comment
Collaborator
There was a problem hiding this comment.
LGTM — verified locally.
- Confirmed the root cause: a stdlib
@dataclasssubclass picks upSearchTerm's class-levelFieldInfoas therelated_termsdefault; both new tests fail againstmain'squery.pyand pass with the fix. Fullmakeis green (813 passed). - Checked the pydantic-dataclass semantics this switches to:
termkeeps its identity (important, since search mutates terms in place), thecast-basedto_required_search_termpath is unaffected, bad input now raisesValidationError, and post-construction assignment stays unvalidated, all the same asSearchTerm. - FYI: a
related_termslist passed to the constructor is now copied (elements keep identity), matchingSearchTerm; nothing insrc//tools/constructsCompiledSearchTermdirectly, so no impact.
(An equally small alternative would have been keeping the stdlib dataclass and redeclaring related_terms: list[Term] | None = None in the subclass, but matching SearchTerm's decorator is the more consistent choice.)
This branch has not been deployed
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
CompiledSearchTermwas a stdlib@dataclasssubclassing the pydantic dataclassSearchTerm. A stdlib dataclass takes the base class's class-level value as the field default, and forrelated_termsthat value is a pydanticFieldInfoobject, notNone.CompiledSearchTerm(Term("x")).related_termswas therefore a truthyFieldInfo, anddedupe_related_termscrashed on it withAttributeError: 'FieldInfo' object has no attribute 'text'.CompiledSearchTermviacast, so it isn't hit there today; tests work around it by always passingrelated_terms=None.CompiledSearchTermwith typeagent's pydanticdataclassdecorator, likeSearchTerm(same import asuniversal_message.py).FieldInfodefault.Relation to #348: #348 changes this default to
Field(default=None, ...), which is still aFieldInfo, so the bug remains there. This PR doesn't touch any file #348 changes; it applies cleanly on top of #348 and the affected tests pass there too.Validation
CompiledSearchTermhasrelated_terms is None, anddedupe_related_termsaccepts such terms. Both fail without the fix.