Conversation
…117) Add Entity.has / Relation.has / <Concrete>.has for finding instances that own a given attribute, optionally filtered by value or expression. Cross-type form (Entity.has(db, Name)) returns mixed concrete subtypes across all entities owning Name. Concrete-class form (HLPerson.has(db, Name)) narrows to that type and its TypeDB subtypes via isa polymorphism — abstract base subclasses get subtype matching for free without any extra branching. Relation results always include hydrated role players. Entity lookups remain single-query; relations are re-fetched per result through concrete_class.manager(connection).get(_iid=iid) to reuse the existing relation manager's role-player extraction. The relation path is therefore N+1 in returned relations, which is acceptable for typical attribute-keyed result sets and is explicitly disclosed in the public docstring. Key changes: - New crud/has_lookup.py with _build_has_query as the single source of truth for query construction, and _hydrate_results split into _hydrate_entity (wildcard fast path) and _hydrate_relation_via_manager (delegates to manager.get for role players). - New TypeDBType.has classmethod that dispatches kind and computes narrow_type via the cls is base_cls check. - Reverse _attribute_owners index in ModelRegistry, populated from Entity / Relation __init_subclass__, plus Attribute.get_owners() for static discovery without a database connection. - Narrowed query uses the existing $t sub <type>; $x isa! $t pattern from crud/typedb_manager.py:597-616. The first attempt with label($x) was rejected by TypeDB 3 because $x is an Object variable, not a Type variable — hence the type-variable dance. Tests: 32 unit + 25 integration covering cross-type, narrowed, and abstract base subclass paths plus role-player hydration on both concrete and cross-type relation receivers.
Ship the #117 cross-type attribute lookup work under v1.4.4 by bumping every workspace version string and regenerating Cargo.lock. Also fix a stale type_bridge.__version__ that was missed by the 1.4.2 and 1.4.3 bump commits — it still read "1.4.1" before this change. Files touched: - pyproject.toml: version + type-bridge-core>= pin - type-bridge-core/pyproject.toml - type-bridge-core/crates/{core,orm,orm-derive,python,server}/Cargo.toml: self version and intra-workspace dependency pins - type-bridge-core/Cargo.lock: regenerated via cargo update -w - type_bridge/__init__.py: __version__ 1.4.1 -> 1.4.4 (carried over) - CHANGELOG.md: new 1.4.4 section summarizing #117 Refs #117
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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