Allow customers to assert facts about the current transaction.#530
Allow customers to assert facts about the current transaction.#530eoger wants to merge 1 commit into
Conversation
| partition_map: &'a PartitionMap, | ||
| schema: &'a Schema, | ||
| mentat_id_count: i64, | ||
| tx_id: Entid, |
| tx_might_update_metadata = true; | ||
| } | ||
|
|
||
| if e == KnownEntid(self.tx_id) && a == entids::DB_TX_INSTANT { |
There was a problem hiding this comment.
You haven't checked that op == OpType::Add!
IMO, the simplest way to do all this work is to make self.tx_instant Option. That means we can get rid of tx_instant_set, skip doing the datom-producing work here, and always do the work down where we used to add txInstant by using unwrap_or.
| } | ||
|
|
||
| if e == KnownEntid(self.tx_id) && a == entids::DB_TX_INSTANT { | ||
| tx_instant_set = true; |
There was a problem hiding this comment.
Consider whether it is an error to have:
[:db/tx :db/txInstant #inst "2017-01-01T10:00:00Z"]
[:db/tx :db/txInstant #inst "2017-01-01T22:00:00Z"]
| panic!("This type error should have been caught earlier."); | ||
| } | ||
| // TODO: INSTANT to be strictly after the last transaction | ||
| // timestamp and strictly before the current transactor timestamp. |
There was a problem hiding this comment.
We might want to weaken this condition — Datomic can assume correct clocks, but embedded clients cannot.
And we will need a way to bypass this, too, for syncing.
| non_fts_one.push((self.tx_id, | ||
| entids::DB_TX_INSTANT, | ||
| self.schema.require_attribute_for_entid(entids::DB_TX_INSTANT).unwrap(), | ||
| TypedValue::Instant(self.tx_instant), |
There was a problem hiding this comment.
So this would be:
self.tx_instant.map_or_else(TypedValue::current_instant, TypedValue::Instant)
| match self { | ||
| TempId::Internal(x) => Some(x), | ||
| TempId::External(_) => None, | ||
| _ => None, |
There was a problem hiding this comment.
The trick you used to find these locations — add the enum case, look for the compile errors — stops working if you use _. Add the explicit TempId::Tx case here instead:
TempId::Internal(x) => Some(x),
TempId::Tx |
TempId::External(_) => None,
87dd6a7 to
e1ea288
Compare
|
Thank you @rnewman, I have amended my patch. |
|
N.B., retractions need to pass through; they conceptually apply before the additions. After working on #533 I think duplicate specifications within a single input should be an error; feel free to define a better error type ("duplicate datom") if one doesn't exist. |
e1ea288 to
7cb44ad
Compare
|
Updated, thanks. |
| self.schema.require_attribute_for_entid(entids::DB_TX_INSTANT).unwrap(), | ||
| TypedValue::Instant(self.tx_instant), | ||
| true)); | ||
| tx_instant = self.tx_instant.unwrap_or(::now()); |
There was a problem hiding this comment.
unwrap_or_else(TypeValue::current_instant).
There was a problem hiding this comment.
Hm, no, the report returns a DateTime. My bad.
| tx_instant = self.tx_instant.unwrap_or(::now()); | ||
|
|
||
| // Transact [:db/add :db/txInstant NOW :db/tx] if it doesn't exist. | ||
| if self.tx_instant == None { |
There was a problem hiding this comment.
You always set tx_instant right above this. I don't think you need this conditional check (or the comment).
There was a problem hiding this comment.
We check self.tx_instant (not tx_instant) here, which is set conditionally in https://github.com/mozilla/mentat/pull/530/files#diff-f0d16e6d633d9a7ec44f52c5f064e75fR624
There was a problem hiding this comment.
Yeah, but the point is: we've filtered out all txInstant-setting datoms from the input. Every tx is supposed to have one. So tx_instant (the local var) is the value we want, and we should always add it to the output. Right?
There was a problem hiding this comment.
Oh, you stripped out the continue. Got it.
Fixes #225