[pycopia] r744 committed - Fix some more bugs associated with upgrading sqlalchemy.

1 view
Skip to first unread message

pyc...@googlecode.com

unread,
Mar 6, 2014, 2:18:15 AM3/6/14
to pyc...@googlegroups.com
Revision: 744
Author: keith.dart
Date: Thu Mar 6 07:17:57 2014 UTC
Log: Fix some more bugs associated with upgrading sqlalchemy.

http://code.google.com/p/pycopia/source/detail?r=744

Modified:
/trunk/storage/pycopia/db/models.py

=======================================
--- /trunk/storage/pycopia/db/models.py Mon Mar 3 19:58:36 2014 UTC
+++ /trunk/storage/pycopia/db/models.py Thu Mar 6 07:17:57 2014 UTC
@@ -1713,7 +1713,13 @@
return mapper.columns[colname].type.get_choices()
except (AttributeError, KeyError):
pass
- mycol = getattr(modelclass, colname)
+ try:
+ mycol = getattr(modelclass, colname)
+ except AttributeError:
+ # If attribute is a backref, it won't exist initially. It needs to
be triggered by using in
+ # a query and fetched again.
+ session.query(modelclass)
+ mycol = getattr(modelclass, colname)
try:
relmodel = mycol.property.mapper.class_
except AttributeError:
@@ -1736,7 +1742,10 @@
except (AttributeError, IndexError):
pass
if order_by:
- q = q.order_by(getattr(relmodel, order_by))
+ order_by = getattr(relmodel, order_by)
+ if type(order_by.property) is RelationshipProperty:
+ q = q.join(order_by)
+ q = q.order_by(order_by)
# Return the list of (id, stringrep) tuples.
# This structure is usable by the XHTML form generator...
return [(relrow.id, str(relrow)) for relrow in q]
@@ -1765,27 +1774,33 @@
if sys.flags.interactive:
from pycopia import interactive

- print (get_metadata(Equipment))
+ #print (get_metadata(Equipment))

- print(inspect(Equipment).get_property("name"))
+ #print(inspect(Equipment).get_property("name"))
assert get_primary_key_name(Equipment) == "id"
- print(get_primary_key_name(Session))
+ #print(get_primary_key_name(Session))

#print (get_column_metadata(Equipment, "interfaces"))
#print (get_column_metadata(Network, "interfaces"))

sess = get_session()

- #choices = XXXget_choices(sess, Equipment, "interfaces", order_by=None)
+ #print (choices)
+ #choices = get_choices(sess, TestCase, "priority", order_by=None)
#print (choices)
- choices = get_choices(sess, TestCase, "priority", order_by=None)
- print (choices)
print (get_choices(sess, Equipment, "interfaces", order_by=None))
- # assumes your host name is in the db for testing.
+ #q = sess.query(Interface).filter(Interface.equipment == None)
+
+ ## assumes your host name is in the db for testing.
+ #print (Equipment.attributes)
+ #print (Equipment.interfaces)
#eq = sess.query(Equipment).filter(Equipment.name.like(os.uname()[1]
+ "%")).one()
+ #print (eq.attributes)
+ #print (Equipment.attributes)
+ #print (Equipment.interfaces)
#print "eq = ", eq
#print "Atributes:"
- #print eq.attributes
+ #print (eq.attributes)
#print "Interfaces:"
#print eq.interfaces
#eq.add_interface(sess, "eth1", interface_type="ethernetCsmacd",
ipaddr="172.17.101.2/24")
Reply all
Reply to author
Forward
0 new messages