ng-galien / idea-plpgdebugger

A plugin to debug PL/pg in Intellij
MIT License
49 stars 8 forks source link

DataGrip Debugger plugin does not load the latest function version #107

Open chernia opened 1 year ago

chernia commented 1 year ago

Describe the bug When a function code is updated, the debugger does not load the new version unless one quits DataGrip and starts it agian.

To Reproduce Steps to reproduce the behavior:

  1. Debug a function
  2. Change its code, verify the function is updated.
  3. Debug again in the same or new console The old code is loaded, unless DataGrip is restarted.

Expected behavior When a function code changes, the debugger should load the new version on every debug run.

Desktop (please complete the following information):

ng-galien commented 1 year ago

Hi,

The plugin shares the Datagrip session. While the stored procedure code is loaded on every debugger step, that's possible the old function definition remains on the active session.

Please test update your code with ensuring the debugger session is closed ( in the task bar on bottom right) AND after deleting or closing your active session in the service panel.

When the stored procedure is updated it should have a different OID displayed on the code editor (in brackets after the procedure name).

Anyway code update workflow remains a big caveat of the debugger, hope this helps until we find a better solution.

chernia commented 1 year ago

Thank you for the fast reply.

I tried closing all sessions, refreshing, deactivating.

The only workaround I found was to Quit/Start DataGrip, which updates the code although the OID in the [ ] debug tab title and left status bar stays the same.

Please let me know if I can help.

Thank you. Ivan

On 17 Jul 2023, at 22:08, Alexandre Boyer @.***> wrote:

Hi,

The plugin shares the Datagrip session. While the stored procedure code is loaded on every debugger step, that's possible the old function definition remains on the active session.

Please test update your code with ensuring the debugger session is closed ( in the task bar on bottom right) AND after deleting or closing your active session in the service panel.

When the stored procedure is updated it should have a different OID displayed on the code editor (in brackets after the procedure name).

Anyway code update workflow remains a big caveat of the debugger, hope this helps until we find a better solution.

— Reply to this email directly, view it on GitHub https://github.com/ng-galien/idea-plpgdebugger/issues/107#issuecomment-1638718251, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALFXXOQGGIGKFA4A5OMQL4DXQWERVANCNFSM6AAAAAA2NA5KVE. You are receiving this because you authored the thread.

ng-galien commented 1 year ago

Seems clearly a bug, thanks for your investigation. What's your PG version?

chernia commented 1 year ago

14

On 19 Jul 2023, at 0:28, Alexandre Boyer @.***> wrote:

Seems clearly a bug, thanks for your investigation. What's your PG version?

— Reply to this email directly, view it on GitHub https://github.com/ng-galien/idea-plpgdebugger/issues/107#issuecomment-1641014761, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALFXXOUQBFPOWDDMRR2Y6DDXQ35WVANCNFSM6AAAAAA2NA5KVE. You are receiving this because you authored the thread.

ng-galien commented 1 year ago

@chernia the fix will be available next week.

chernia commented 1 year ago

Seems fine, but something else pops up: [ERROR] Query failed LIST_BREAKPOINT ERROR: select() failed waiting for target (com.intellij.database.remote.jdbc.SQLExceptionWithProperties: ERROR: select() failed waiting for target) The debugger hangs with lot of [01000] cache reference leak: cache pg_type (80), tuple 0/10 has count 577 and the breakpoint is left.

ng-galien commented 1 year ago

@chernia here is my setup and test scenario:

CREATE OR REPLACE FUNCTION inner_debug(IN p_text text)
    RETURNS text
    LANGUAGE plpgsql
AS
$function$
    DECLARE
        v_test text;
BEGIN
    --Test
    v_test = p_text;
    v_test = v_test || ' -INNER -' || current_timestamp;
    return v_test;
end
$function$;

CREATE TABLE debug
(
    id   serial,
    name text
);

INSERT INTO debug (name) VALUES ('Debug 1');
INSERT INTO debug (name) VALUES ('Debug 2');

CREATE TYPE custom_type AS
(
    id   integer,
    name text
);

CREATE OR REPLACE FUNCTION public.test_debug(p_text text, p_int integer DEFAULT 0)
    RETURNS text
    LANGUAGE plpgsql
AS
$function$
DECLARE
    v_int_array   INT[]       = ARRAY [6, 7, 8];
    v_custom      custom_type = (434, 'Custom')::custom_type;
    v_debug_array debug[];
    v_debug       debug;
    v_text        TEXT        = 'hchc';
    v_int         INT         = 45;
    v_date        date        = NULL;
BEGIN
    --Test
    v_text = p_text;
    v_text = v_text || ' -' || current_timestamp;
    v_text = v_text || ' -' || current_timestamp;
    v_int_array = array_append(v_int_array, p_int);
    SELECT * FROM debug limit 1 into v_debug;
    v_int_array = array_append(v_int_array, 3);
    SELECT array_agg(d) FROM debug d into v_debug_array;
    v_int_array = array_append(v_int_array, 5);
    v_int_array = array_append(v_int_array, 7);
    v_text = inner_debug(p_text);
    v_int = v_int + 1;
    v_date = current_date;
    SELECT array_agg(id) FROM debug into v_int_array;
    return 'DEBUG END';
end
$function$;

In ran this

CREATE EXTENSION IF NOT EXISTS pldbgapi;
SELECT * FROM test_debug('ZZEZ', 1);
  1. Debug the select with the button (SELECT * FROM test_debug('ZZEZ', 1);
  2. At the first time the top breakpoint does not shows up 👎
  3. Stop the debug session
  4. Put a breakpoint
  5. Restart debug with the button
  6. Stops a the breakpoint
  7. Variables are quite ok
  8. Stop the debug session
  9. Modify public.test_debug
  10. Restart debug with the button
  11. Check the source code have changed
  12. Repeat from 6

Could you please provide more information that I can reproduce the problem? Thanks! (If you use the same docker images on my docker hub repo, please update it because I've made some changes to it)

chernia commented 1 year ago

Thanks the test is fine. Reloads code. Once I got an error: [ERROR] Query failed LIST_BREAKPOINT ERROR: select() failed waiting for target (com.intellij.database.remote.jdbc.SQLExceptionWithProperties: ERROR: select() failed waiting for target) but could not reproduce.

Unfortunately on some functions, the Debug window closes immediately and when I open it, it says Nothing to show. How to find the problem? Do I need to set search_path in functions or session is enough?