Re: [sqlalchemy] Unable to configure Column server_default attribute when using automap

2017-02-01 Thread mike bayer




On 02/01/2017 01:54 PM, derek.mil...@spacex.com wrote:

It doesn't appear that the "default" column_info field allows for
anything other than a generic default. I currently have the following
event handler:

|
@event.listens_for(Table,'column_reflect')
def_set_fetched_value_for_triggered_columns(inspector,table,column_info):
ifcolumn_info['name']in('current_version_num','version_num'):
column_info['default']=FetchedValue()
|



and am getting the following failure on reflection:


bind parameter names, add them

# to the list of bindparams

 self.text =self._bind_params_regex.sub(repl,text)

E   TypeError:expected stringorbuffer


/lib/python2.7/site-packages/sqlalchemy/sql/elements.py:1238:TypeError

|


Looking at the code

 it
explicitly wraps it in a text object. Thoughts?


this is

https://bitbucket.org/zzzeek/sqlalchemy/issues/3905/column_reflect-cant-allow-non-textual

review is pending at https://gerrit.sqlalchemy.org/#/c/305/






Thanks,
Derek


On Wednesday, February 1, 2017 at 8:20:34 AM UTC-8, Mike Bayer wrote:

you would use the column_reflect event and set the value of the
"default" in the given dictionary to be your FetchedValue object.



On 01/31/2017 05:06 PM, derek@spacex.com  wrote:
> I am attempting to reflect an existing PostgreSQL database that has
> triggers setting a version_num column. Reading the docs SQLAlchemy
needs
> to be told the the value is a FetchedValue(), however there is no
way to
> do this via the the "column_reflect" event handler. I also
attempted to
> manually define the column on the table but it then excludes the
column
> from the entire reflection process. Is there any other way to do
this or
> can 'server_default' be added to the list of allowed column_info
keys?
>
> Thanks,
> Derek
>
> --
> SQLAlchemy -
> The Python SQL Toolkit and Object Relational Mapper
>
> http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and
> Verifiable Example. See http://stackoverflow.com/help/mcve
 for a full
> description.
> ---
> You received this message because you are subscribed to the Google
> Groups "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it,
send
> an email to sqlalchemy+...@googlegroups.com 
> .
> To post to this group, send email to sqlal...@googlegroups.com

> .
> Visit this group at https://groups.google.com/group/sqlalchemy
.
> For more options, visit https://groups.google.com/d/optout
.

--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and
Verifiable Example. See http://stackoverflow.com/help/mcve for a full
description.
---
You received this message because you are subscribed to the Google
Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to sqlalchemy+unsubscr...@googlegroups.com
.
To post to this group, send email to sqlalchemy@googlegroups.com
.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper


http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.

To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Unable to configure Column server_default attribute when using automap

2017-02-01 Thread derek . miller
It doesn't appear that the "default" column_info field allows for anything 
other than a generic default. I currently have the following event handler:

@event.listens_for(Table, 'column_reflect')
def _set_fetched_value_for_triggered_columns(inspector, table, column_info):
if column_info['name'] in ('current_version_num', 'version_num'):
column_info['default'] = FetchedValue()



and am getting the following failure on reflection:

...
/lib/python2.7/site-packages/sqlalchemy/engine/reflection.py:657
: in _reflect_column

sql.text(col_d['default']), _reflected=True
/lib/python2.7/site-packages/sqlalchemy/sql/elements.py:1379: in 
_create_text
stmt = TextClause(text, bind=bind)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
_ _ 


self = 
text = FetchedValue(), bind = None


def __init__(
self,
text,
bind=None):
self._bind = bind
self._bindparams = {}

def repl(m):
self._bindparams[m.group(1)] = BindParameter(m.group(1))
return ':%s' % m.group(1)

# scan the string and search for bind parameter names, add them
# to the list of bindparams
>   self.text = self._bind_params_regex.sub(repl, text)
E   TypeError: expected string or buffer


/lib/python2.7/site-packages/sqlalchemy/sql/elements.py:1238: 
TypeError



Looking at the code 

 it 
explicitly wraps it in a text object. Thoughts?

Thanks,
Derek


On Wednesday, February 1, 2017 at 8:20:34 AM UTC-8, Mike Bayer wrote:
>
> you would use the column_reflect event and set the value of the 
> "default" in the given dictionary to be your FetchedValue object. 
>
>
>
> On 01/31/2017 05:06 PM, derek@spacex.com  wrote: 
> > I am attempting to reflect an existing PostgreSQL database that has 
> > triggers setting a version_num column. Reading the docs SQLAlchemy needs 
> > to be told the the value is a FetchedValue(), however there is no way to 
> > do this via the the "column_reflect" event handler. I also attempted to 
> > manually define the column on the table but it then excludes the column 
> > from the entire reflection process. Is there any other way to do this or 
> > can 'server_default' be added to the list of allowed column_info keys? 
> > 
> > Thanks, 
> > Derek 
> > 
> > -- 
> > SQLAlchemy - 
> > The Python SQL Toolkit and Object Relational Mapper 
> > 
> > http://www.sqlalchemy.org/ 
> > 
> > To post example code, please provide an MCVE: Minimal, Complete, and 
> > Verifiable Example. See http://stackoverflow.com/help/mcve for a full 
> > description. 
> > --- 
> > You received this message because you are subscribed to the Google 
> > Groups "sqlalchemy" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> > an email to sqlalchemy+...@googlegroups.com  
> > . 
> > To post to this group, send email to sqlal...@googlegroups.com 
>  
> > . 
> > Visit this group at https://groups.google.com/group/sqlalchemy. 
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Unable to configure Column server_default attribute when using automap

2017-02-01 Thread mike bayer
you would use the column_reflect event and set the value of the 
"default" in the given dictionary to be your FetchedValue object.




On 01/31/2017 05:06 PM, derek.mil...@spacex.com wrote:

I am attempting to reflect an existing PostgreSQL database that has
triggers setting a version_num column. Reading the docs SQLAlchemy needs
to be told the the value is a FetchedValue(), however there is no way to
do this via the the "column_reflect" event handler. I also attempted to
manually define the column on the table but it then excludes the column
from the entire reflection process. Is there any other way to do this or
can 'server_default' be added to the list of allowed column_info keys?

Thanks,
Derek

--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and
Verifiable Example. See http://stackoverflow.com/help/mcve for a full
description.
---
You received this message because you are subscribed to the Google
Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to sqlalchemy+unsubscr...@googlegroups.com
.
To post to this group, send email to sqlalchemy@googlegroups.com
.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper


http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.

To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] Unable to configure Column server_default attribute when using automap

2017-01-31 Thread derek . miller
I am attempting to reflect an existing PostgreSQL database that has 
triggers setting a version_num column. Reading the docs SQLAlchemy needs to 
be told the the value is a FetchedValue(), however there is no way to do 
this via the the "column_reflect" event handler. I also attempted to 
manually define the column on the table but it then excludes the column 
from the entire reflection process. Is there any other way to do this or 
can 'server_default' be added to the list of allowed column_info keys?

Thanks,
Derek

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.