473,543 Members | 2,383 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Type error when using SQLAlchemy and Python


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.obje cts ) 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.


from Registry import *

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


from Manager import *

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

class Model(object):
__metaclass__=M odelBase

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

if __name__=='__ma in__':
a = Manager(InterPr o)
print a
print a.all() --this prints out all of the objects in the database
i = InterPro('IPR01 4697')
print InterPro.object s
print InterPro.object s.all()
--this fails and produces the exception.

Traceback (most recent call last):
File "Model.py ", line 28, in ?
print InterPro.object s.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_whe reclause(wherec lause=arg, **kwargs)
File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/query.py",
line 252, in select_wherecla use
return self._select_st atement(stateme nt, params=params)
File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/query.py",
line 378, in _select_stateme nt
return self.execute(st atement, 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._in stance(context, row, result)
File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/mapper.py",
line 1213, in _instance
instance = self._create_in stance(context. session)
File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/mapper.py",
line 1234, in _create_instanc e
obj = self.class_.__n ew__(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 1415

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

Similar topics

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 about the extended slice that the slice object would describe if applied to a sequence of length items. It returns a tuple of three integers; respectively these are the /start/ and /stop/ indices and...
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 what everyone's preference is, and why, and if there are even more choices for ORM. Thanks.
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 wrong. After searching a little, it seems it's one of those hard to get down to cases, so I've no idea where to look for. Briefly what I do is, select some rows from one table, do some number...
by: Ilias Lazaridis | last post by:
- Ï/Ç metaperl: Ilias Lazaridis: Michael Bayer wrote within: http://groups.google.com/group/sqlalchemy/msg/9d7a096a61abfc6f I understand your elaborations.
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 without having to make copies of all attributes? class Derived (Base): def __init__ (self, base_object): # ( copy all attributes ) ...
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 indirectly with SQLAlchemy? If so, can someone please provide an example? If not, how do I obtain the raw cx_Oracle cursor so I can use callfunc directly on that? Thanks, Greg
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> import sqlalchemy.mods.threadlocal from sqlalchemy import DynamicMetaData, objectstore
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 or more tables - create a new sqlite database file and open a connection to it - write out the previously-read tables and their contents to this new database
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 language for automating tasks. The current script that I am working on requires pulling in some information from a Microsoft SQL Server. I was wondering if anyone could suggest the best way of...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.