Skip to content
← Back to activity

Immutable solution version

Rewrite in abstract types possible?

Version 1Sign in to save

Complete solution

Comparing objects with = only compares ids, so to bump a revision only when properties actually changed, compare the unpacked JSON property sets: rewrite update using ( (__old__.rev + 1) if exists ((select json_object_unpack([json]__subject__{*}) except json_object_unpack([json]__old__{*}))) else __old__.rev ); The maintainer confirmed this works for detecting property changes. Caveat from the thread: this is a workaround, not the idiomatic way.

What was reported: Issue geldata/gel#5883 (closed, 12 comments): - EdgeDB Version: 4.0-dev.7696+eae6d5a

  • EdgeDB CLI Version: 3.5.0-dev.1025+fec3413
  • OS Version: Linux hp 6.1.39-1-lts #1 SMP PREEMPTDYNAMIC Wed, 19 Jul 2023 17:58:31 +0000 x8664 GNU/Linux

Steps to Reproduce:

  1. insert Foo { name := "f1" };
  2. update Foo set { name := "f1" };
InternalServerError: could not resolve trailing pointer class for (__derived__::__old__)
Hint: This is most likely a bug in EdgeDB. Please consider opening an issue ticket at https://github.com/edgedb/edgedb/issues/new?template=bug_report.md

Schema:

abstract type Revisable {
 ...

What works:
Comparing objects with `=` only compares ids, so to bump a revision only when properties actually changed, compare the unpacked JSON property sets:

rewrite update using (
  (__old__.rev + 1)
  if exists ((select json_object_unpack([json]__subject__{*})
              except json_object_unpack([json]__old__{*})))
  else __old__.rev
);

The maintainer confirmed this works for detecting property changes. Caveat from the thread: this is a workaround, not the idiomatic way. A proper structural comparison (something like `std::eq_properties()`) does not exist yet; it is tracked separately as issue #5335.

Evidence

In the GitHub issue, the reporter asked: Rewrite in abstract types possible?. The working answer that came out of the thread: Comparing objects with = only compares ids, so to bump a revision only when properties actually changed, compare the unpacked JSON property sets:

rewrite update using ( (old.rev + 1) if exists ((select jsonobjectunpack([json]subject{}) except jsonobjectunpack([json]old{}))) else old.rev );

The maintainer confirmed this works for detecting property changes. Caveat from the thread: this is a workaround, not the idiomatic way. A proper structural comparison (something like std::eq_properties()) does not exist yet; it is tracked separately as issue #5335. Source: https://github.com/geldata/gel/issues/5883

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_UKBdaHuya4QskKSR7ARlmw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Rewrite in abstract types possible? <span>— Vectle</span></a>