473,324 Members | 2,531 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 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 1401

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 about the extended slice that the slice object would...
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 what everyone's preference is, and why, and if...
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 wrong. After searching a little, it seems it's one...
6
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.
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 without having to make copies of all attributes? ...
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 indirectly with SQLAlchemy? If so, can someone please...
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> import sqlalchemy.mods.threadlocal from sqlalchemy...
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 or more tables - create a new sqlite database file...
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 language for automating tasks. The current script...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.