[sqlalchemy] Re: out of range / locate column / lost connection
braydon fuller wrote: That's the part I don't get is that it shouldn't be empty... I may have fixed this by using 'try', and then returning 'None' if it fails. [EMAIL PROTECTED] wrote: first two mean the result of the query is empty. On Friday 06 June 2008 01:49:23 braydon fuller wrote: I am having some database problems (attached below), any recommendations to either recover from or fix these from happening? I am not sure why it would work OK at first, and then at some point run bad... Any recommendations on a technique to debug this would be much appreciated. Full source code of the project can be browsed here: http://git.braydon.com/gitweb.cgi?p=sparrow;a=tree;h=refs/heads/mas ter;hb=refs/heads/master For an idea of the project (screencast... although slightly old): http://interfce.com/videos/sparrow.html The site this is coming from (live): http://mochilla.com/ [05/Jun/2008:22:16:15] HTTP Traceback (most recent call last): File /var/lib/python-support/python2.5/cherrypy/_cprequest.py, line 550, in respond cherrypy.response.body = self.handler() File /var/lib/python-support/python2.5/cherrypy/_cpdispatch.py, line 24, in __call__ return self.callable(*self.args, **self.kwargs) File /var/local/mochilla/sparrow/http.py, line 38, in default return render(args, kwargs, location_st) File /var/local/mochilla/sparrow/templates.py, line 363, in render return render_skeleton(location, location_st, kwargs) File /var/local/mochilla/sparrow/templates.py, line 266, in render_skeleton body, cmds_array = compile_templates(location, kwargs) File /var/local/mochilla/sparrow/templates.py, line 192, in compile_templates doc = get_uri(location) File /var/local/mochilla/sparrow/uri.py, line 31, in get_uri selected = db.session.query(TemplateRelation).filter_by(location=uri)[0] File /var/lib/python-support/python2.5/sqlalchemy/orm/query.py, line 844, in __getitem__ return list(self[item:item+1])[0] IndexError: list index out of range 127.0.0.1 - - [05/Jun/2008:22:15:44] GET / HTTP/1.0 500 3293 [05/Jun/2008:22:15:59] HTTP Traceback (most recent call last): File /var/lib/python-support/python2.5/cherrypy/_cprequest.py, line 550, in respond cherrypy.response.body = self.handler() File /var/lib/python-support/python2.5/cherrypy/_cpdispatch.py, line 24, in __call__ return self.callable(*self.args, **self.kwargs) File /var/local/mochilla/sparrow/http.py, line 38, in default return render(args, kwargs, location_st) File /var/local/mochilla/sparrow/templates.py, line 363, in render return render_skeleton(location, location_st, kwargs) File /var/local/mochilla/sparrow/templates.py, line 266, in render_skeleton body, cmds_array = compile_templates(location, kwargs) File /var/local/mochilla/sparrow/templates.py, line 252, in compile_templates data = search_list(doc.oid, doc.objects, location=location, locations=locations, cmds_array=doc.cmds_array, kwargs=kwargs) File /var/local/mochilla/sparrow/templates.py, line 172, in search_list objects = object_children(object_oid) File /var/local/mochilla/sparrow/objects.py, line 39, in object_children parent = get_object(oid) File /var/local/mochilla/sparrow/objects.py, line 31, in get_object selected = db.session.query(Objects).filter_by(oid=oid).one() File /var/lib/python-support/python2.5/sqlalchemy/orm/query.py, line 927, in one raise exceptions.InvalidRequestError('No rows returned for one()') InvalidRequestError: No rows returned for one() 127.0.0.1 - - [05/Jun/2008:18:15:08] GET / HTTP/1.0 200 24400 [05/Jun/2008:18:15:09] HTTP Traceback (most recent call last): File /var/lib/python-support/python2.5/cherrypy/_cprequest.py, line 550, in respond cherrypy.response.body = self.handler() File /var/lib/python-support/python2.5/cherrypy/_cpdispatch.py, line 24, in __call__ return self.callable(*self.args, **self.kwargs) File /var/lib/python-support/python2.5/cherrypy/_cptools.py, line 140, in handle_func handled = self.callable(*args, **self._merged_args(kwargs)) TypeError: staticfile() got multiple values for keyword argument 'filename' class 'sqlalchemy.exceptions.NoSuchColumnError' [05/Jun/2008:21:42:22] HTTP Traceback (most recent call last): File /var/lib/python-support/python2.5/cherrypy/_cprequest.py, line 550, in respond cherrypy.response.body = self.handler() File /var/lib/python-support/python2.5/cherrypy/_cpdispatch.py, line 24, in __call__ return self.callable(*self.args, **self.kwargs) File /var/local/mochilla/sparrow/http.py, line 38, in default return render(args, kwargs, location_st) File /var/local/mochilla/sparrow/templates.py, line 346, in render get_uri(location_id) File /var/local/mochilla/sparrow/uri.py, line 31, in get_uri selected = db.session.query(TemplateRelation).filter_by(location=uri)[0] File /var/lib/python-support
[sqlalchemy] out of range / locate column / lost connection
I am having some database problems (attached below), any recommendations to either recover from or fix these from happening? I am not sure why it would work OK at first, and then at some point run bad... Any recommendations on a technique to debug this would be much appreciated. Full source code of the project can be browsed here: http://git.braydon.com/gitweb.cgi?p=sparrow;a=tree;h=refs/heads/master;hb=refs/heads/master For an idea of the project (screencast... although slightly old): http://interfce.com/videos/sparrow.html The site this is coming from (live): http://mochilla.com/ [05/Jun/2008:22:16:15] HTTP Traceback (most recent call last): File /var/lib/python-support/python2.5/cherrypy/_cprequest.py, line 550, in respond cherrypy.response.body = self.handler() File /var/lib/python-support/python2.5/cherrypy/_cpdispatch.py, line 24, in __call__ return self.callable(*self.args, **self.kwargs) File /var/local/mochilla/sparrow/http.py, line 38, in default return render(args, kwargs, location_st) File /var/local/mochilla/sparrow/templates.py, line 363, in render return render_skeleton(location, location_st, kwargs) File /var/local/mochilla/sparrow/templates.py, line 266, in render_skeleton body, cmds_array = compile_templates(location, kwargs) File /var/local/mochilla/sparrow/templates.py, line 192, in compile_templates doc = get_uri(location) File /var/local/mochilla/sparrow/uri.py, line 31, in get_uri selected = db.session.query(TemplateRelation).filter_by(location=uri)[0] File /var/lib/python-support/python2.5/sqlalchemy/orm/query.py, line 844, in __getitem__ return list(self[item:item+1])[0] IndexError: list index out of range 127.0.0.1 - - [05/Jun/2008:22:15:44] GET / HTTP/1.0 500 3293 [05/Jun/2008:22:15:59] HTTP Traceback (most recent call last): File /var/lib/python-support/python2.5/cherrypy/_cprequest.py, line 550, in respond cherrypy.response.body = self.handler() File /var/lib/python-support/python2.5/cherrypy/_cpdispatch.py, line 24, in __call__ return self.callable(*self.args, **self.kwargs) File /var/local/mochilla/sparrow/http.py, line 38, in default return render(args, kwargs, location_st) File /var/local/mochilla/sparrow/templates.py, line 363, in render return render_skeleton(location, location_st, kwargs) File /var/local/mochilla/sparrow/templates.py, line 266, in render_skeleton body, cmds_array = compile_templates(location, kwargs) File /var/local/mochilla/sparrow/templates.py, line 252, in compile_templates data = search_list(doc.oid, doc.objects, location=location, locations=locations, cmds_array=doc.cmds_array, kwargs=kwargs) File /var/local/mochilla/sparrow/templates.py, line 172, in search_list objects = object_children(object_oid) File /var/local/mochilla/sparrow/objects.py, line 39, in object_children parent = get_object(oid) File /var/local/mochilla/sparrow/objects.py, line 31, in get_object selected = db.session.query(Objects).filter_by(oid=oid).one() File /var/lib/python-support/python2.5/sqlalchemy/orm/query.py, line 927, in one raise exceptions.InvalidRequestError('No rows returned for one()') InvalidRequestError: No rows returned for one() 127.0.0.1 - - [05/Jun/2008:18:15:08] GET / HTTP/1.0 200 24400 [05/Jun/2008:18:15:09] HTTP Traceback (most recent call last): File /var/lib/python-support/python2.5/cherrypy/_cprequest.py, line 550, in respond cherrypy.response.body = self.handler() File /var/lib/python-support/python2.5/cherrypy/_cpdispatch.py, line 24, in __call__ return self.callable(*self.args, **self.kwargs) File /var/lib/python-support/python2.5/cherrypy/_cptools.py, line 140, in handle_func handled = self.callable(*args, **self._merged_args(kwargs)) TypeError: staticfile() got multiple values for keyword argument 'filename' class 'sqlalchemy.exceptions.NoSuchColumnError' [05/Jun/2008:21:42:22] HTTP Traceback (most recent call last): File /var/lib/python-support/python2.5/cherrypy/_cprequest.py, line 550, in respond cherrypy.response.body = self.handler() File /var/lib/python-support/python2.5/cherrypy/_cpdispatch.py, line 24, in __call__ return self.callable(*self.args, **self.kwargs) File /var/local/mochilla/sparrow/http.py, line 38, in default return render(args, kwargs, location_st) File /var/local/mochilla/sparrow/templates.py, line 346, in render get_uri(location_id) File /var/local/mochilla/sparrow/uri.py, line 31, in get_uri selected = db.session.query(TemplateRelation).filter_by(location=uri)[0] File /var/lib/python-support/python2.5/sqlalchemy/orm/query.py, line 844, in __getitem__ return list(self[item:item+1])[0] File /var/lib/python-support/python2.5/sqlalchemy/orm/query.py, line 986, in iterate_instances rows = [process[0](context, row) for row in fetch] File /var/lib/python-support/python2.5/sqlalchemy/orm/query.py, line 1551, in main
[sqlalchemy] Re: cherrypy, sqlachemy, mod_wsgi, and apache2
Michael Bayer wrote: On Feb 4, 2008, at 8:34 PM, braydon fuller wrote: This is the wrong way to go about insuring that there is a DB connection. I'd like to know the correct way. Would this be to test the database, and if that fails to open a connection? well I dont know cherrypy so i dont see anything familiar to me there. but as far as SA is concerned, it would like you to create a single engine just once in your application. after that you dont need to worry about ensuring the DB is connected, it takes care of it for you. I have a Borg that has the db connection and session in it. Do I need to reconnect the connection or close and open a new session for a long running web app? Below is the Class i'm using: class Database(object): db = get_database(settings.database) def __init__(self): self.engine = Database.db.engine self.connection = Database.db.connection self.session = Database.db.session def create_all(self): metadata.create_all(self.engine) def start_engine(self): Database.db = get_database(settings.database) class DB(object): def __init__(self, engine=None, connection=None, session=None): self.engine = engine self.connection = connection self.session = session def get_database(info): info = info info_list = [] info_list.append(info.database) info_list.append(://) info_list.append(info.user) info_list.append(:) info_list.append(info.password) info_list.append(@) info_list.append(info.host) info_list.append(:) info_list.append(info.port) info_list.append(/) info_list.append(info.database_name) info_list.append(pool_recycle=3600, pool_timeout=30, max_overflow=10, pool_size=5) info_url_list = [] for info in info_list: info_url_list.append(info.replace('\','')) info_url = .join(info_url_list) db = DB() db.engine = create_engine(info_url) db.connection = db.engine.connect() Session = sessionmaker(bind=db.connection) db.session = Session() return db --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: cherrypy, sqlachemy, mod_wsgi, and apache2
Michael Bayer wrote: there seems to be more going on there, but perhaps are all side effects of the same thing: http://www.sqlalchemy.org/trac/wiki/FAQ#MySQLserverhasgoneawaypsycopg.InterfaceError:connectionalreadyclosed or otherwise your mysql client is not able to connect at all. I have switched to trying postgresql, to see what shows up. The new problem being that it appears I have WAY TOO MANY processes open to the database being made: braydon 24226 0.2 8.5 339524 33536 pts/2Sl Feb04 0:13 python http_server.py postgres 24229 0.0 1.7 102416 6968 ?Ss Feb04 0:00 postgres: braydon braydon 127.0.0.1(35089) idle in transaction postgres 24233 0.0 1.6 102300 6356 ?Ss Feb04 0:00 postgres: braydon braydon 127.0.0.1(35093) idle postgres 24277 0.0 1.2 101876 4836 ?Ss Feb04 0:00 postgres: braydon braydon 127.0.0.1(35564) idle postgres 24412 0.0 1.2 101876 4840 ?Ss 00:02 0:00 postgres: braydon braydon 127.0.0.1(59737) idle postgres 24483 0.0 1.2 101876 4836 ?Ss 00:17 0:00 postgres: braydon braydon 127.0.0.1(53032) idle postgres 24547 0.0 1.2 101876 4840 ?Ss 00:32 0:00 postgres: braydon braydon 127.0.0.1(33366) idle postgres 24675 0.0 1.2 101876 4840 ?Ss 01:00 0:00 postgres: braydon braydon 127.0.0.1(54586) idle postgres 24676 0.0 1.2 101880 4840 ?Ss 01:00 0:00 postgres: braydon braydon 127.0.0.1(54589) idle postgres 24677 0.0 1.2 101876 4828 ?Ss 01:00 0:00 postgres: braydon braydon 127.0.0.1(54591) idle postgres 24736 0.0 1.2 101876 4832 ?Ss 01:12 0:00 postgres: braydon braydon 127.0.0.1(51563) idle postgres 24741 0.0 1.2 101876 4840 ?Ss 01:13 0:00 postgres: braydon braydon 127.0.0.1(51579) idle postgres 24743 0.0 1.2 101876 4844 ?Ss 01:13 0:00 postgres: braydon braydon 127.0.0.1(51585) idle postgres 24756 0.0 1.2 101876 4844 ?Ss 01:15 0:00 postgres: braydon braydon 127.0.0.1(42054) idle postgres 24773 0.0 0.5 100724 2148 ?Ds 01:18 0:00 postgres: autovacuum worker process I am using the following to establish get the database going: import cherrypy from sparrow.settings import Settings from sparrow.database import Database from sparrow.templates import render db = Database() settings = Settings() class Root(): def __init__(self): self.cmd = __import__('exposed', globals(), locals(),['sparrow']) db.create_all() def default(self, *args, **kwargs): location_st = for arg in args: location_st += /+arg try: return render(args, kwargs, location_st) except: db.start_engine() return render(args, kwargs, location_st) default.exposed = True This is the wrong way to go about insuring that there is a DB connection. I'd like to know the correct way. Would this be to test the database, and if that fails to open a connection? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: cherrypy, sqlachemy, mod_wsgi, and apache2
Michael Bayer wrote: there seems to be more going on there, but perhaps are all side effects of the same thing: http://www.sqlalchemy.org/trac/wiki/FAQ#MySQLserverhasgoneawaypsycopg.InterfaceError:connectionalreadyclosed or otherwise your mysql client is not able to connect at all. I have switched to trying postgresql, to see what shows up. The new problem being that it appears I have WAY TOO MANY processes open to the database being made: braydon 24226 0.2 8.5 339524 33536 pts/2Sl Feb04 0:13 python http_server.py postgres 24229 0.0 1.7 102416 6968 ?Ss Feb04 0:00 postgres: braydon braydon 127.0.0.1(35089) idle in transaction postgres 24233 0.0 1.6 102300 6356 ?Ss Feb04 0:00 postgres: braydon braydon 127.0.0.1(35093) idle postgres 24277 0.0 1.2 101876 4836 ?Ss Feb04 0:00 postgres: braydon braydon 127.0.0.1(35564) idle postgres 24412 0.0 1.2 101876 4840 ?Ss 00:02 0:00 postgres: braydon braydon 127.0.0.1(59737) idle postgres 24483 0.0 1.2 101876 4836 ?Ss 00:17 0:00 postgres: braydon braydon 127.0.0.1(53032) idle postgres 24547 0.0 1.2 101876 4840 ?Ss 00:32 0:00 postgres: braydon braydon 127.0.0.1(33366) idle postgres 24675 0.0 1.2 101876 4840 ?Ss 01:00 0:00 postgres: braydon braydon 127.0.0.1(54586) idle postgres 24676 0.0 1.2 101880 4840 ?Ss 01:00 0:00 postgres: braydon braydon 127.0.0.1(54589) idle postgres 24677 0.0 1.2 101876 4828 ?Ss 01:00 0:00 postgres: braydon braydon 127.0.0.1(54591) idle postgres 24736 0.0 1.2 101876 4832 ?Ss 01:12 0:00 postgres: braydon braydon 127.0.0.1(51563) idle postgres 24741 0.0 1.2 101876 4840 ?Ss 01:13 0:00 postgres: braydon braydon 127.0.0.1(51579) idle postgres 24743 0.0 1.2 101876 4844 ?Ss 01:13 0:00 postgres: braydon braydon 127.0.0.1(51585) idle postgres 24756 0.0 1.2 101876 4844 ?Ss 01:15 0:00 postgres: braydon braydon 127.0.0.1(42054) idle postgres 24773 0.0 0.5 100724 2148 ?Ds 01:18 0:00 postgres: autovacuum worker process I am using the following to establish get the database going: import cherrypy from sparrow.settings import Settings from sparrow.database import Database from sparrow.templates import render db = Database() settings = Settings() class Root(): def __init__(self): self.cmd = __import__('exposed', globals(), locals(),['sparrow']) db.create_all() def default(self, *args, **kwargs): location_st = for arg in args: location_st += /+arg try: return render(args, kwargs, location_st) except: db.start_engine() return render(args, kwargs, location_st) default.exposed = True This is the wrong way to go about insuring that there is a DB connection. I'd like to know the correct way. Would this be to test the database, and if that fails to open a connection? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] sync tables/columns
Hello, Is there a way to use SQLAlchemy to update my already created database tables, so that if I were to take: audio_table = Table('objects_audio', metadata, Column('id', Integer, primary_key=True), Column('oid',Integer, ForeignKey(objects.oid)), Column('src', String(1000)) ) and add, or modify a few columns: audio_table = Table('objects_audio', metadata, Column('id', Integer, primary_key=True), Column('oid',Integer, ForeignKey(objects.oid)), Column('src', String(1000)), Column('format', String(1000)), Column('length', String(1000)), Column('size', String(1000)) ) it would create the new columns, as well as update changes with existing columns? -- bgfuller braydon.com 626.298.6570 land 323.841.0048 air 117.121.243.13 web LA CA USA --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---
[sqlalchemy] Re: Is there a way to replace object in DB?
you can also use 'try' to avoid error messages: def ensure_object(db, id): try: o = db.Query(ModelObject).get(id) except: o = ModelObject(1, u'title') db.save(o) db.commit() return o -Braydon Rick Morrison wrote: ...if you're just checking to see if something exists in the database, why not just try to .load() it, and then construct it afresh if you don't find it? This kind of operation is sometimes called an upsert ...some database engines support it, some don't. Most don't. But what all database engines DO support is a query, followed by either an insert, or an update as appropriate. Here's the idiom that should work: def ensure_object(sess, id): o = sess.Query(ModelObject).get(id)# if found, o is now loaded into session if not o: o = ModelObject(1, u'title' sess.save(o) sess.flush() return o --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~--~~~~--~~--~--~---