what do you want p.data to return ? leaving it undefined is enough for the
ORM to consider it as "unloaded". Your best option here would be just to not
map the column (see the exclude_columns argument for that).
On Jun 21, 2010, at 5:48 AM, GHZ wrote:
> including small example
>
> in the actual case, I can't find anything as obvious as the equivalent
> of 'print t.data' in my code.. but something is triggering these
> selects of columns with defaults
>
>
>
>
> from sqlalchemy import MetaData, create_engine, Table, Column, Integer
> from sqlalchemy.orm import mapper, sessionmaker, relationship
>
> engine = create_engine('oracle://bob:b...@mig01', echo=True)
> meta = MetaData(bind=engine)
>
> ddls = [
> """drop table t""",
> """create table t (id number primary key,
> data number default null)
> """
> ]
>
> for ddl in ddls:
> engine.execute(ddl)
>
>
> t = Table('t', meta, autoload=True, useexisting=True)
>
> meta.create_all()
>
> class T(object):
> pass
>
> session = sessionmaker()()
>
> mapper(T, t)
>
> p = T()
> p.id = 1
> session.add(p)
> session.flush()
>
> print p.data
>
>
>
>
>
> 2010-06-21 11:41:46,168 INFO sqlalchemy.engine.base.Engine.0x...84ec
> {'table_name': u'T', 'schema': u'BOB'}
> 2010-06-21 11:41:46,173 INFO sqlalchemy.engine.base.Engine.0x...84ec
> SELECT table_name FROM all_tables WHERE table_name = :name AND owner
> = :schema_name
> 2010-06-21 11:41:46,173 INFO sqlalchemy.engine.base.Engine.0x...84ec
> {'name': u'T', 'schema_name': u'BOB'}
> 2010-06-21 11:41:46,184 INFO sqlalchemy.engine.base.Engine.0x...84ec
> BEGIN
> 2010-06-21 11:41:46,185 INFO sqlalchemy.engine.base.Engine.0x...84ec
> INSERT INTO t (id) VALUES (:id)
> 2010-06-21 11:41:46,186 INFO sqlalchemy.engine.base.Engine.0x...84ec
> {'id': 1}
> 2010-06-21 11:41:46,215 INFO sqlalchemy.engine.base.Engine.0x...84ec
> SELECT t.data AS t_data
> FROM t
> WHERE t.id = :param_1
> 2010-06-21 11:41:46,215 INFO sqlalchemy.engine.base.Engine.0x...84ec
> {'param_1': 1}
>
> On 21 Jun, 11:40, GHZ <[email protected]> wrote:
>> Hi,
>>
>> If I create a table with a default.
>>
>> create table T (id number primary key, data number default NULL)
>>
>> Then reflect this table.
>>
>> then using the ORM I trigger an insert, but only into the id column
>> and flush()
>> then I try to access the 'data' attribute
>>
>> this causes a select, to get the actual value of 'data'
>>
>> Is there any simple way to turn this behavior off`.. i.e for
>> sqlalchemy to pretend the server default does not exist..?
>>
>> Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/sqlalchemy?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.