Hi all!

I'm using 0.7.3 and I am facing a problem.

The problem is that I'm using the get_history function from
sqlalchemy.orm.attributes to get the history from a composite property
of an object. When the composite property is set, everything is ok,
but when it is not set, I get an error.

This is an example I have written to demonstrate the problem:

=============================

from sqlalchemy import Column, Integer
from sqlalchemy.orm import composite
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm.attributes import get_history

Base = declarative_base()

class Point(object):
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __composite_values__(self):
        return self.x, self.y

    def __repr__(self):
        return "Point(x=%r, y=%r)" % (self.x, self.y)

    def __eq__(self, other):
        return isinstance(other, Point) and other.x == self.x and
other.y == self.y

    def __ne__(self, other):
        return not self.__eq__(other)


class Example(Base):
    __tablename__ = 'example'
    id = Column(Integer, primary_key=True)
    x = Column(Integer)
    y = Column(Integer)
    point = composite(Point, x, y)


success = Example()
success.point = Point(1,2)
get_history(success, 'point')

fail = Example()
get_history(fail, 'point')

===============================

For the first example the property is set, and we can get the history.
But for the second object the property has not been set and when we
call get_history an error will occur.

This is the stacktrace:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    get_history(fail, 'point')
  File "/**/python2.7/site-packages/sqlalchemy/orm/attributes.py",
line 1168, in get_history
    return get_state_history(instance_state(obj), key, passive)
  File "/**/python2.7/site-packages/sqlalchemy/orm/attributes.py",
line 1171, in get_state_history
    return state.get_history(key, passive)
  File "/**/python2.7/site-packages/sqlalchemy/orm/state.py", line
104, in get_history
    return self.manager[key].impl.get_history(self, self.dict,
passive)
  File "/**/python2.7/site-packages/sqlalchemy/orm/
descriptor_props.py", line 40, in get_history
    return prop.get_history(state, dict_, passive)
  File "/**/python2.7/site-packages/sqlalchemy/orm/
descriptor_props.py", line 258, in get_history
    (),[self.composite_class(*added)], ()
TypeError: __init__() takes exactly 3 arguments (1 given)

It looks like an instance of a Point will be created without
parameters.

Is this a programming error?

Cheers!

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to