Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

empty ch_group_edit #1322

Open
cquiroz opened this issue Jul 24, 2024 · 2 comments
Open

empty ch_group_edit #1322

cquiroz opened this issue Jul 24, 2024 · 2 comments

Comments

@cquiroz
Copy link
Contributor

cquiroz commented Jul 24, 2024

I'm implementing deleting an observation in the context of the calibrations process
I managed to make the deletion but I get a bogus ch_group_edit event producing the error:
Invalid group and/or event: Notification(28296,ch_group_edit,)

The last entry is the value of the notification.

I have examined the places where triggers produce a group_edit and I can't see how it can be empty

@cquiroz
Copy link
Contributor Author

cquiroz commented Jul 24, 2024

These are the places where a group edit is produced

  • ch_group_edit
CREATE OR REPLACE FUNCTION ch_group_edit()
  RETURNS trigger AS $$
DECLARE
BEGIN
  PERFORM pg_notify('ch_group_edit', NEW.c_group_id || ',' || NEW.c_program_id || ',' || nextval('s_event_id')::text || ',' || TG_OP);
  RETURN NEW; -- n.b. doesn't matter, it's an AFTER trigger
END;
$$ LANGUAGE plpgsql;
  • ch_obs_group_edit
 CREATE OR REPLACE FUNCTION ch_obs_group_edit()
  RETURNS trigger AS $$
DECLARE
BEGIN
  -- notify old group, if any
  IF (TG_OP = 'UPDATE' OR TG_OP = 'DELETE') THEN
    PERFORM pg_notify('ch_group_edit', coalesce(OLD.c_group_id, 'null') || ',' || NEW.c_program_id || ',' || 'UPDATE');
  END IF;
  -- notify new group, if any
  IF (TG_OP = 'INSERT' OR TG_OP = 'UPDATE' OR TG_OP = 'DELETE') THEN
      PERFORM pg_notify('ch_group_edit', coalesce(NEW.c_group_id, 'null') || ',' || NEW.c_program_id || ',' || 'UPDATE');
  END IF;
  RETURN NEW; -- n.b. doesn't matter, it's an AFTER trigger
END;
$$ LANGUAGE plpgsql;

@cquiroz
Copy link
Contributor Author

cquiroz commented Jul 25, 2024

ok this is coming from a null NEW.c_program_id. I wonder if fixing it would be a matter of doing coalesce(NEW.c_program_id, OLD.c_program_id)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant