schemainspect
schemainspect copied to clipboard
Exception inspecting a table or composite type referencing an enum from an extension
This looks similar to #59, but with enums. The error occurs a little earlier, in load_all_relations
.
To reproduce this problem you need an extension containing composite type containing an enum. I couldn't find anything like that in the standard postgresql distribution, so I put together a dummy extension. This short script will create the extension, or you can grab the archive linked below and unpack it in your postgresql share dir.
pgsharedir=$(pg_config --sharedir)
cat >$pgsharedir/extension/dummy.control <<'EOF'
# dummy extension
comment = 'dummy test extension'
default_version = '0.0.1'
relocatable = true
EOF
cat >$pgsharedir/extension/dummy--0.0.1.sql <<'EOF'
SET client_min_messages = warning;
CREATE TYPE color AS ENUM (
'blue',
'teal',
'aqua',
'grey',
'eggshell');
CREATE TYPE colorpair AS (
a color,
b color);
EOF
Once the extension is installed, the following schema should reproduce the problem.
create extension dummy;
create table foo (id serial primary key, xx colorpair);
Traceback (most recent call last):
File ".../bin/migra", line 3, in <module>
import re
File ".../lib/python3.6/site-packages/migra/command.py", line 108, in do_command
status = run(args)
File ".../lib/python3.6/site-packages/migra/command.py", line 79, in run
m = Migration(ac0, ac1, schema=schema, exclude_schema=exclude_schema)
File ".../lib/python3.6/site-packages/migra/migra.py", line 26, in __init__
x_from, schema=schema, exclude_schema=exclude_schema
File ".../lib/python3.6/site-packages/schemainspect/get.py", line 20, in get_inspector
inspected = ic(c)
File ".../lib/python3.6/site-packages/schemainspect/pg/obj.py", line 1060, in __init__
super(PostgreSQL, self).__init__(c, include_internal)
File ".../lib/python3.6/site-packages/schemainspect/inspector.py", line 25, in __init__
self.load_all()
File ".../lib/python3.6/site-packages/schemainspect/pg/obj.py", line 1064, in load_all
self.load_all_relations()
File ".../lib/python3.6/site-packages/schemainspect/pg/obj.py", line 1319, in load_all_relations
for c in clist
File ".../lib/python3.6/site-packages/schemainspect/pg/obj.py", line 1320, in <listcomp>
if c.position_number
File ".../lib/python3.6/site-packages/schemainspect/pg/obj.py", line 1302, in get_enum
return self.enums[quoted_full_name]
KeyError: '"sterling"."rrule_freq"'
It just occurred to me that this might be an unusual corner case because the enum is in a composite type.
I'll try to put some steps to reproduce the problem together.
This also occurs without the composite type, if the extension enum is used in a table.
The following approach seems to work to get past this:
- Add an
is_extension
flag toInspectedEnum
- Modify the query in pg/sql/enums.sql to return an
is_extension
column instead of filtering out extensions - In migra, customize
Changes.enums
to filter out enums that haveis_extension
on
If this approach seems reasonable, I can put together some PRs.
Hey, thanks heaps for filing this issue and investigating! PRs would be very welcome. If you have any questions just let me know.
@groner Is there any progress on this or anything I can do to help this along? This same issue is blocking me from using migra in my project!
@jaredramirez I haven't looked at this in over a year, but I think #63 addresses this. Not sure how up to date it is now though.