I do not pretend to fully understand what the the triggers/functions are really doing,
but I did notice this:
create or replace function populate_community_zoid_triggerf()
...
new_zoid := NEW.state ->> 'community_zoid'; zoid := find_community_zoid( NEW.zoid, NEW.class_name, NEW.state)::text; if zoid is null then if new_zoid is not null then NEW.state := NEW.state - 'community_zoid'; end if; else if new_zoid is null or zoid != new_zoid then NEW.state := NEW.state || ('{"community_zoid": ' || zoid || '}')::jsonb; end if; end if;
...
Not sure what happens if zoid is null and new_zoid is null also?
Then then no change is needed and nothing happens, which is correct.