Skip to content

Dependency missed with a function used as default value #191

@the-glu

Description

@the-glu

Hello,

I have an issue with the following schema:

CREATE FUNCTION public.demo() RETURNS text
    LANGUAGE plpgsql
    AS $$
declare
begin
   return 'hi';
end;

$$;

CREATE TABLE public.demo2 (
    demo3 text DEFAULT public.demo() NOT NULL
);

The dependency between demo2 and demo is not detected, validation is not passing.

validating migration plan: running migration plan: executing migration statement: {DROP FUNCTION "public"."demo"() 3s 3s [HAS_UNTRACKABLE_DEPENDENCIES: Dependencies, i.e. other functions used in the function body, of non-sql functions cannot be tracked. As a result, we cannot guarantee that function dependencies are ordered properly relative to this statement. For drops, this means you need to ensure that all functions this function depends on are dropped after this statement.]}: ERROR: cannot drop function demo() because other objects depend on it (SQLSTATE 2BP01)

With generated statements lookings like this:

        {
            DDL:         "DROP FUNCTION \"public\".\"demo\"()",
            Timeout:     3000000000,
            LockTimeout: 3000000000,
            Hazards:     {
                {Type:"HAS_UNTRACKABLE_DEPENDENCIES", Message:"Dependencies, i.e. other functions used in the function body, of non-sql functions cannot be tracked. As a result, we cannot guarantee that function dependencies are ordered properly relative to this statement. For drops, this means you need to ensure that all functions this function depends on are dropped after this statement."},
            },
        },
        {
            DDL:         "DROP TABLE \"public\".\"demo2\"",
            Timeout:     1200000000000,
            LockTimeout: 3000000000,
            Hazards:     {
                {Type:"DELETES_DATA", Message:"Deletes all rows in the table (and the table itself)"},
            },
        },

I do understand that there are complexities tracking dependencies of functions, but could a 'obvious' dependency like that one, when the function is explicitly used somewhere else be detected?

I tried to dig a into the code but I was not sure where / how to find relevents part, if you have some pointers I would be happy to make a PR to improve that :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions