noload() is used only for multi-table relations(), to indicate that a secondary relation should not be eager or lazy loaded.
what youre looking for is almost like "deferred column loading" (http://www.sqlalchemy.org/docs/ adv_datamapping.myt#advdatamapping_properties_deferred) but i guess you are doing this more for security reasons rather than performance. i dont know if SA really has a feature that exactly fits that idea...you could try making a second mapper that maps to a select statement, which doesnt include the column that you want to obscure. or, just have your mapped object "hide" the field (youre not exposing the object to untrusted code, are you?) On Jun 26, 2006, at 9:16 PM, Brad Clements wrote: > SVN revision 1666 > > I am looking at "More on Mapper Options" on > > http://sqlalchemy.org/docs/adv_datamapping.myt > > I have a generic wsgi middleware that takes a table name and > returns data from > that table. > > For one table, I want to hide one field. That is, for table named > 'coordinator' I > want to NOT return the c_password field (but only when accessed via > wsgi) > > So from the above URL it looks like I could do this > > from sqlalchemy import * > from sqlalchemy.mods.threadlocal import * > from sqlalchemy.schema import default_metadata > > Tcoordinator = Table('coordinator', metadata, > Column('region_id', > Integer, > primary_key=True, > nullable=False, > ), > Column('id', > Integer, > Sequence("coordinator_id", optional=True), > primary_key=True, > nullable=False, > ), > Column('c_password', > String(12), > nullable=False, > ), > ) > > class coordinator(object): > pass > > assign_mapper(coordinator, Tcoordinator) > > > # now, coordinator should be a mapper object itself?) > > if request_method == 'GET': > if table_name == 'coordinator': > table = coordinator # actually done via a getattr on > a module > # modify the mapper > table = table.options(noload('c_password')) > > record = table.get(int(id)) > results = { > 'table_name':table_name, > 'id':id, > 'record':record or None, > } > > But this doesn't work, I get: > > File 'E:\\prj\\src\\eclipse\\parent_to_parent\\Web\\p2pserver\ > \p2pserver\\dbaccess.py', line 50 in __call__ > table = table.options(noload('c_password')) > exceptions.AttributeError: type object 'coordinator' has no > attribute 'options' > > > I thought that assign_mapper assigned all the attributes of a > mapper to it's class > (get, select, etc) > > But maybe options was left out? > > So then I tried this: > > if table_name == 'coordinator': > # modify the mapper > table = table.mapper.options(noload('c_password')) > > > But now I get this error: > > File 'E:\\prj\\src\\eclipse\\parent_to_parent\\Web\\p2pserver\ > \p2pserver\\database.py', line 42 in __call__ > ok_callback=manager.finish) > File 'e:\\prj\\src\\paste\\paste\\wsgilib.py', line 114 in > catch_errors > app_iter = application(environ, start_response) > File 'e:\\prj\\src\\paste\\paste\\urlmap.py', line 202 in __call__ > return app(environ, start_response) > File 'E:\\prj\\src\\eclipse\\parent_to_parent\\Web\\p2pserver\ > \p2pserver\\dbaccess.py', line 51 in __call__ > table = table.mapper.options(noload('c_password')) > File 'e:\\prj\\src\\sqlalchemy\\lib\\sqlalchemy\\orm\\mapper.py', > line 717 in options > option.process(mapper) > File 'e:\\prj\\src\\sqlalchemy\\lib\\sqlalchemy\\orm\ > \properties.py', line 643 in process > self.process_by_key(mapper, self.key) > File 'e:\\prj\\src\\sqlalchemy\\lib\\sqlalchemy\\orm\ > \properties.py', line 652 in process_by_key > self.create_prop(mapper, tokens[0]) > File 'e:\\prj\\src\\sqlalchemy\\lib\\sqlalchemy\\orm\ > \properties.py', line 729 in create_prop > mapper._compile_property(key, newprop) > File 'e:\\prj\\src\\sqlalchemy\\lib\\sqlalchemy\\orm\\mapper.py', > line 602 in _compile_property > prop.init(key, self) > File 'e:\\prj\\src\\sqlalchemy\\lib\\sqlalchemy\\orm\\mapper.py', > line 1167 in init > self.do_init(key, parent) > File 'e:\\prj\\src\\sqlalchemy\\lib\\sqlalchemy\\orm\ > \properties.py', line 198 in do_init > if isinstance(self.argument, type): > exceptions.AttributeError: 'PropertyLoader' object has no attribute > 'argument' > > > So then I tried this instead (pretty much copied from the website) > > if table_name == 'coordinator': > # modify the mapper > table = class_mapper(table).options(noload > ('c_password')) > > But I get the same exception: > exceptions.AttributeError: 'PropertyLoader' object has no attribute > 'argument' > > What am I doing wrong? > > > > > -- > Brad Clements, [EMAIL PROTECTED] (315)268-1000 > http://www.murkworks.com > AOL-IM or SKYPE: BKClements > > > > Using Tomcat but need to do more? Need to support web services, > security? > Get stuff done quickly with pre-integrated technology to make your > job easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache > Geronimo > http://sel.as-us.falkag.net/sel? > cmd=lnk&kid=120709&bid=263057&dat=121642 > _______________________________________________ > Sqlalchemy-users mailing list > Sqlalchemy-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Sqlalchemy-users mailing list Sqlalchemy-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users