Resolve forward lookup refs in transactions, apply value predicates to entity ids - #16
Merged
Merged
Conversation
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
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
Two engine fixes for issues hit by the logseq db-worker port.
1. Forward lookup refs inside a transaction are deferred, not fatal
An entity map (or
[:db/add]op) whose ref-attr value is a lookup ref pointing at an entity defined by a later op in the same tx previously raisedInvalid_argument "Nothing found for entity id [:block/uuid <b>]"fromTransact.resolve_entity_ref. Example:resolve_entity_ref'sLookup_refarm now raises a dedicatedUnresolved_lookup_ref of attr * valueexception instead ofInvalid_argumentwhen the ref doesn't resolve against the datoms accumulated so far.apply_opscatches it, rolls back the op atomically (tx state is immutable), and queues the op ondeferred_ops;drain_deferred_opsretries pending ops in original order as the tx accumulates datoms."Nothing found for entity id"Invalid_argument, so genuinely missing targets still error exactly as before (upstream parity for real misses).One_value,Many_valuescollections, entity-map attrs,Adde- and v-positions,CompareAndSet, and nested/tx-fn-produced ops. The bulk fast path (try_apply_bulk_explicit_entities) falls back to the sequential path when an eager lookup fails.Note on upstream semantics: upstream DataScript itself raises on forward lookup refs (logseq's cljs handles this case in outliner preprocessing via
stable-entity-ref-with-tx-data). This is a documented, requested divergence so the engine can run logseq's real transactions directly.2. Value/numeric predicates now see entity-id bindings
[(even? ?x)],number?,integer?, etc. over a variable bound to an entity id returned no rows. Entity ids are plain numbers upstream; the port wraps them asRef/Result_entityand two places dropped them:eval_value_predicate_clause(and the same pattern inparse_complement_predicate_clause) only matchedResult_value; it now converts viavalue_of_query_result(Result_entity e → Ref e).Built_ins.matches_numeric_predicate/matches_value_predicate/numeric_valuenow treatRef easInt e— consistent withcompare_value, which already comparesRefnumerically.This is what makes upstream's "Joining regular clauses with rule" test (
[_ _ ?x] (rule ?x ?y) [(even? ?x)]) pass — it returned empty before.Verified-not-broken (kept as regression tests)
:parent/:class-extendsrule shape and upstream's mutually-recursive-rules case both pass.avetafter restore: sqlite-restored dbs index ref-attr values and answer_attrreverse patterns; covered bytest_sqlite_storage_restored_reverse_ref_lookup(andmemory_storagerestore empirically).[?x ...]collection:in: already covered by PR Fix query-engine bugs: :in predicate bindings, intra-tx lookup refs, EDN symbol chars #15'scollection_in_binding.New tests in
test_query_engine_fixes:entity_map_lookup_ref_later_tx_entity,_many_values,add_op_lookup_ref_later_tx_entity,entity_map_lookup_ref_never_resolves_raises,logseq_parent_rule,mutually_recursive_rules,rule_joined_with_clauses— all verified fail-before/pass-after where a repro existed. Fulldune runtestgreen including upstream parity.Link to Devin session: https://app.devin.ai/sessions/c82925b6976a4a6da2688c410e65011a
Open in Devin Desktop: https://app.devin.ai/desktop/session/c82925b6976a4a6da2688c410e65011a?variant=devin
Requested by: @tiensonqin