472,352 Members | 1,490 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,352 software developers and data experts.

Type error when using SQLAlchemy and Python

HI,

I posted this to sqlalchemy but didnt get a response, so I was
wondering if anyone on python-list could help me.

I m currently trying to build an api for a database and I really like
the way that Djangos manager ( Class_name.objects ) is set up. This
seems very intuitive for me. After reading through the some of the
django source and getting slightly confused I ve implemented a basic
version for one of my tables. The problem is I get an exception, when
I m not expecting one.

registry.py --contains table definitions etc.

Manager.py

from Registry import *

class Manager(object):
def __init__(self, model, table=None):
self.model = model
self.table = table
def get(self, slice):
pass
def all(self):
print "1"
mapper(self.model, interpro_table)
print "2"
session = create_session()
print "3"
query = session.query(self.model)
print "4"
return query.select()

Models.py

from Manager import *

class ModelBase(type):
def __new__(cls, name, bases, dict):
print cls
setattr(cls, 'objects', Manager(cls))
return type.__new__(cls, name, bases, dict)

class Model(object):
__metaclass__=ModelBase

class InterPro(Model):
_tableName = interpro_table
def __init__(self, interpro_ac):
self.interpro_ac = interpro_ac
def __str__(self):
return "InterPro: %s" %(self.interpro_ac)
def __repr__(self):
return "InterPro: %s" %(self.interpro_ac)

if __name__=='__main__':
a = Manager(InterPro)
print a
print a.all() --this prints out all of the objects in the database
i = InterPro('IPR014697')
print InterPro.objects
print InterPro.objects.all()
--this fails and produces the exception.

Traceback (most recent call last):
File "Model.py ", line 28, in ?
print InterPro.objects.all()
File "/home/skeg/workspace/test/src/Manager.py", line 17, in all
return query.select()
File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/query.py",
line 247, in select
return self.select_whereclause(whereclause=arg, **kwargs)
File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/query.py",
line 252, in select_whereclause
return self._select_statement(statement, params=params)
File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/query.py",
line 378, in _select_statement
return self.execute(statement, params=params, **kwargs)
File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/query.py",
line 310, in execute
return self.instances(result, **kwargs)
File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/query.py",
line 329, in instances
self.mapper._instance(context, row, result)
File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/mapper.py",
line 1213, in _instance
instance = self._create_instance(context.session)
File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/mapper.py",
line 1234, in _create_instance
obj = self.class_.__new__(self.class_)
TypeError: __new__() takes exactly 4 arguments (1 given)

Does anyone know what the problem is? Is it the way I ve programmed
this using metaclasses or is it sqlalchemy and the way in instantiates
objects or even both?

Many Thanks in advance,
Jun 11 '07 #1
0 1330

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

108
by: Bryan Olson | last post by:
The Python slice type has one method 'indices', and reportedly: This method takes a single integer argument /length/ and computes information...
20
by: John Salerno | last post by:
Are there any major differences between these two? It seems they can both be used with TurboGears, and SQLAlchemy with Django. I'm just wondering...
2
by: George Sakkis | last post by:
It's the first time in the three years I've been using python that a program crashes without a nice traceback to give me a clue of what might be...
6
by: Ilias Lazaridis | last post by:
- Ï/Ç metaperl: Ilias Lazaridis: Michael Bayer wrote within: http://groups.google.com/group/sqlalchemy/msg/9d7a096a61abfc6f I understand...
11
by: Frederic Rentsch | last post by:
Hi all, If I derive a class from another one because I need a few extra features, is there a way to promote the base class to the derived one...
3
by: Greg Copeland | last post by:
I'm using SQLAlchemy and have a need to call an Oracle function; which is not the same as a stored procedure. Can this be done directory or...
2
by: Adam Kubica | last post by:
Hello. I have pylons 0.96 (SVN) and current SQLAlchemy (0.3.10), and I have bug that doesn't exist earlier. My connection code: <code>...
0
by: Ben Sizer | last post by:
Hello, I'd like to be able to do the following: - open a connection to a MySQL or PostgreSQL database - read the schema and contents for one...
2
by: hwcowan | last post by:
Hello, I have programmed before, but I am new to using Python. I am currently using the ArcGIS software which uses Python as its scripting...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.