[sqlalchemy] Shouldn't MetaData.reflect() be able to reflect views, too?

104 views
Skip to first unread message

stephan

unread,
May 3, 2010, 8:54:01 AM5/3/10
to sqlalchemy
We currently use your SQLAlchemy and it is just great.

We are in the process of updating to SQLAlchemy 0.6 and I found one
change due to the new handling of reflection in MetaData.reflect(),
file schema.py. Basically, reflect() is unchanged. But due to the new
implementation of bind.engine.table_names, it can only reflect tables
and no longer views (contrary to what was possible for many RDBS in
version 0.5).

Relevant piece of code in MetaData.reflect() is (unchanged between 0.5
and 0.6):

available = util.OrderedSet(bind.engine.table_names(schema,

connection=conn))

Shouldn't 'available' be amended to include views (possibly optional),
given that reflection of views is supported now out of the box without
problems? Or am I overlooking something?

I know that I can easily get MetaData for views elsewhere (and do so
for the time being). I just suggest this feature as, for me, it looks
natural to add this functionality to reflect().

--
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To post to this group, send email to sqlal...@googlegroups.com.
To unsubscribe from this group, send email to sqlalchemy+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.

Michael Bayer

unread,
May 3, 2010, 12:54:28 PM5/3/10
to sqlal...@googlegroups.com

On May 3, 2010, at 8:54 AM, stephan wrote:

> We currently use your SQLAlchemy and it is just great.
>
> We are in the process of updating to SQLAlchemy 0.6 and I found one
> change due to the new handling of reflection in MetaData.reflect(),
> file schema.py. Basically, reflect() is unchanged. But due to the new
> implementation of bind.engine.table_names, it can only reflect tables
> and no longer views (contrary to what was possible for many RDBS in
> version 0.5).
>
> Relevant piece of code in MetaData.reflect() is (unchanged between 0.5
> and 0.6):
>
> available = util.OrderedSet(bind.engine.table_names(schema,
>
> connection=conn))
>
> Shouldn't 'available' be amended to include views (possibly optional),
> given that reflection of views is supported now out of the box without
> problems? Or am I overlooking something?
>
> I know that I can easily get MetaData for views elsewhere (and do so
> for the time being). I just suggest this feature as, for me, it looks
> natural to add this functionality to reflect().

was not aware that metadata.reflect() was doing views in 0.5, and this feature is fine if someone has time to work on it. (trac ticket is a good start)

stephan

unread,
May 5, 2010, 5:05:22 AM5/5/10
to sqlalchemy

> was not aware that metadata.reflect() was doing views in 0.5, and this feature is fine if someone has time to work on it.    (trac ticket is a good start)

Below is a tiny diff that allows for reflection of views (so that our
0.5.7-version based unit test passes without changes again). Haven't
tested beyond this.

If you agree, I will attach this to a ticket which I will create on
your wiki.


1870c1870
< conn = None
---
> conn = bind.engine.contextual_connect()
1879a1880,1881
> available.update(bind.engine.dialect.get_view_names(conn,
> schema=schema))
Reply all
Reply to author
Forward
0 new messages