Skip to content

Commit

Permalink
Conditionally inject dependencies of functions
Browse files Browse the repository at this point in the history
For some functions, it is possible that the functions it depends
upon are not explicitly present, e.g. for the following aggregate
function:

CREATE AGGREGATE array_agg_mult(anyarray) (
    SFUNC = array_cat,
    STYPE = anyarray,
    INITCOND = '{}'
);

We got the following error when trying to dbtoyaml this database

KeyError: (u'public', 'array_cat', u'anyarray, anyarray'), but
the dependency is upon pg_catalog.array_cat, so should not even be
made explicit.
  • Loading branch information
Feike Steenbergen committed May 17, 2018
1 parent 167cf2a commit fb29ccb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pyrseas/dbobject/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,8 @@ def get_implied_deps(self, db):
args = self.arguments.replace(' ORDER BY', ',')
else:
args = self.stype + ', ' + self.arguments
deps.add(db.functions[sch, fnc, args])
if (sch, fnc, args) in db.functions:
deps.add(db.functions[sch, fnc, args])
for fn in ('finalfunc', 'mfinalfunc'):
if getattr(self, fn) is not None:
func = getattr(self, fn)
Expand Down
12 changes: 12 additions & 0 deletions tests/functional/pagila-schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ CREATE AGGREGATE group_concat(text) (

ALTER AGGREGATE public.group_concat(text) OWNER TO postgres;

--
-- Name: array_agg_mult(anyarray); Type: AGGREGATE; Schema: public; Owner: postgres
--
CREATE AGGREGATE array_agg_mult(anyarray) (
SFUNC = array_cat,
STYPE = anyarray,
INITCOND = '{}'
);


ALTER AGGREGATE public.array_agg_mult(anyarray) OWNER TO postgres;

--
-- Name: category_category_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--
Expand Down

0 comments on commit fb29ccb

Please sign in to comment.