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

Random order in flow_steps #9580

Open
jguedon opened this issue Feb 23, 2024 · 1 comment
Open

Random order in flow_steps #9580

jguedon opened this issue Feb 23, 2024 · 1 comment

Comments

@jguedon
Copy link

jguedon commented Feb 23, 2024

Describe the bug

Hi,

I’m working with the latest version of gravitee (4.2.0) and postresql (15.1).

I’ve created a script that allows me to create api into gravitee via a rest request (“management/v2/environments/DEFAULT/apis/_import/definition”) and to start it (“management/v2/environments/DEFAULT/apis/${id}/_start”).

The api is imported and started but flow_steps in policies are randomly added.

For example, api has A → B → C as flows. After import, i’ll have B->A->C or C->B->A.

This issue is also occurs when I update a flow_steps from the interface.

To Reproduce

Steps to reproduce the behaviour:

  1. Create an api with several policies
  2. Export api via the interface
  3. Check that all flow_steps are in the right order in the exported json
  4. Import api via the interface or via rest api
  5. Go to the policies of the created api and see random flow_steps

Expected behaviour

Reimporting an api should keep flow_steps order.

Useful information

I’ve tried to analyze how the db is made and the only thing I’ve seen so far is that order in flow_steps table is always inserted with 0. Not sure if this is relevant.

Environment

gravitee 4.2.0

Potential impacts

Dependencies

https://community.gravitee.io/t/random-order-in-flow-steps/2396/1

@jguedon
Copy link
Author

jguedon commented Mar 8, 2024

Temporary fix for PSQL database :

CREATE SEQUENCE flow_steps_order_sequence;
ALTER TABLE flow_steps ALTER COLUMN "order" SET DEFAULT nextval('flow_steps_order_sequence');
ALTER SEQUENCE flow_steps_order_sequence OWNER TO <your_db_user>;
ALTER SEQUENCE flow_steps_order_sequence OWNED BY flow_steps.order;

CREATE OR REPLACE FUNCTION ignore_auto_increment_column()
RETURNS TRIGGER AS $$
BEGIN
RAISE NOTICE 'Executing trigger: ignore_auto_increment_column';

NEW."order" := nextval('flow_steps_order_sequence');
RAISE NOTICE 'Order value updated to: %', NEW."order";

RETURN NEW;

END;
$$ LANGUAGE plpgsql;

CREATE TRIGGER before_insert_trigger
BEFORE INSERT ON flow_steps
FOR EACH ROW
EXECUTE FUNCTION ignore_auto_increment_column();

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

No branches or pull requests

1 participant