Re: [sqlalchemy] Merge support with ConcreteInheritedProperty

2010-08-02 Thread Kent Bower

Excellent.  The 'pass' ConcreteInheritedProperty.merge() method works fine.

Thanks again.


On 8/1/2010 2:24 PM, Michael Bayer wrote:

On Jul 31, 2010, at 7:41 AM, Kent wrote:

   

When I call merge() on an ArTran object, the merge() method of a
ConcreteInheritedProperty 'artransarchiveid'
that *exists only on ArTranArchive* is being called.
 

The attribute artransarchiveid also exists on your base mapper, since the base mapper is mapped 
to a polymorphic union of all the subclasses.   The ConcreteInheritedProperty is placed on 
subclasses which don't have any way to map this attribute, i.e. all your subclasses that are on tables which 
don't have that column.   This is one of the awkwardnesses to the current system of a concrete map with no 
real superclass.

If the polymorphic union were generated only against columns that were common 
to all subclasses, you wouldn't have such attributes in the end result, but 
then each subclass would invoke a second SELECT to load its remaining 
attributes (I just tried this to confirm it is the case).If the mapper knew 
that only a subset of columns are common to subclasses, and that another bunch 
of attributes were only for loading, that could make this cleaner still by not 
mapping those extra attributes on the base, but it hasn't been worked out how 
that would function or be configured.

   

(
As an aside, instead of getting a 'NotImplementedError' when
ConcreteInheritedProperty.merge() is called, I am getting TypeError:
merge() takes exactly 6 arguments (8 given)
 

anyway a do-nothing merge() has been added to ConcreteInheritedProperty in 
r3b1895a3b736 which allows merge() to work with a concrete mapping.

   


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@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.



Re: [sqlalchemy] Merge support with ConcreteInheritedProperty

2010-08-01 Thread Michael Bayer

On Jul 31, 2010, at 7:41 AM, Kent wrote:

 
 When I call merge() on an ArTran object, the merge() method of a
 ConcreteInheritedProperty 'artransarchiveid'
 that *exists only on ArTranArchive* is being called.

The attribute artransarchiveid also exists on your base mapper, since the 
base mapper is mapped to a polymorphic union of all the subclasses.   The 
ConcreteInheritedProperty is placed on subclasses which don't have any way to 
map this attribute, i.e. all your subclasses that are on tables which don't 
have that column.   This is one of the awkwardnesses to the current system of a 
concrete map with no real superclass. 

If the polymorphic union were generated only against columns that were common 
to all subclasses, you wouldn't have such attributes in the end result, but 
then each subclass would invoke a second SELECT to load its remaining 
attributes (I just tried this to confirm it is the case).If the mapper knew 
that only a subset of columns are common to subclasses, and that another bunch 
of attributes were only for loading, that could make this cleaner still by not 
mapping those extra attributes on the base, but it hasn't been worked out how 
that would function or be configured.

 (
 As an aside, instead of getting a 'NotImplementedError' when
 ConcreteInheritedProperty.merge() is called, I am getting TypeError:
 merge() takes exactly 6 arguments (8 given)

anyway a do-nothing merge() has been added to ConcreteInheritedProperty in 
r3b1895a3b736 which allows merge() to work with a concrete mapping.

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@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.



[sqlalchemy] Merge support with ConcreteInheritedProperty

2010-07-31 Thread Kent
I'm having a problem trying to merge() an object for which I have
setup a polymorphic_union:

artran_union = polymorphic_union({
'artran': artrans_table,
'archive': artransarchive_table
}, 'type', 'artran_union')

artranbase_mapper = mapper(ArTranBase, artran_union,
polymorphic_on=artran_union.c.type,
properties={'trancode': relation(TranCode,
cascade='refresh-expire,expunge', lazy=False),
'paymenttype': relation(PaymentType,
cascade='refresh-expire,expunge', lazy=False)}
)


# --- ArTran
mapper(ArTran, artrans_table, inherits=artranbase_mapper,
concrete=True, polymorphic_identity='artran',
properties={'trancode': relation(TranCode,
cascade='refresh-expire,expunge', lazy=False),
'paymenttype': relation(PaymentType,
cascade='refresh-expire,expunge', lazy=False)}
)


# - ArTranArchive
mapper(ArTranArchive, artransarchive_table,
inherits=artranbase_mapper,
concrete=True, polymorphic_identity='archive',
properties={'trancode': relation(TranCode,
cascade='refresh-expire,expunge', lazy=False),
'paymenttype': relation(PaymentType,
cascade='refresh-expire,expunge', lazy=False)}
)


When I call merge() on an ArTran object, the merge() method of a
ConcreteInheritedProperty 'artransarchiveid'
that *exists only on ArTranArchive* is being called.

Have I set something up incorrectly or is this a bug?

(
As an aside, instead of getting a 'NotImplementedError' when
ConcreteInheritedProperty.merge() is called, I am getting TypeError:
merge() takes exactly 6 arguments (8 given)
I think you need to update the MapperProperty interface's merge()
definition from
def merge(self, session, source, dest, load, _recursive):
-
def merge(self, session, source_state, source_dict, dest_state,
dest_dict, load, _recursive):
)

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@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.



Re: [sqlalchemy] Merge support with ConcreteInheritedProperty

2010-07-31 Thread Michael Bayer

On Jul 31, 2010, at 7:41 AM, Kent wrote:

 I'm having a problem trying to merge() an object for which I have
 setup a polymorphic_union:
 
 artran_union = polymorphic_union({
'artran': artrans_table,
'archive': artransarchive_table
}, 'type', 'artran_union')
 
 artranbase_mapper = mapper(ArTranBase, artran_union,
polymorphic_on=artran_union.c.type,
properties={'trancode': relation(TranCode,
cascade='refresh-expire,expunge', lazy=False),
'paymenttype': relation(PaymentType,
cascade='refresh-expire,expunge', lazy=False)}
)
 
 
 # --- ArTran
 mapper(ArTran, artrans_table, inherits=artranbase_mapper,
concrete=True, polymorphic_identity='artran',
properties={'trancode': relation(TranCode,
cascade='refresh-expire,expunge', lazy=False),
'paymenttype': relation(PaymentType,
cascade='refresh-expire,expunge', lazy=False)}
)
 
 
 # - ArTranArchive
 mapper(ArTranArchive, artransarchive_table,
 inherits=artranbase_mapper,
concrete=True, polymorphic_identity='archive',
properties={'trancode': relation(TranCode,
cascade='refresh-expire,expunge', lazy=False),
'paymenttype': relation(PaymentType,
cascade='refresh-expire,expunge', lazy=False)}
)
 
 
 When I call merge() on an ArTran object, the merge() method of a
 ConcreteInheritedProperty 'artransarchiveid'
 that *exists only on ArTranArchive* is being called.

well its going to call upon the properties of ArTranBase, I gather you've used 
pdb and such to figure out that ArTranArchive is the direct parent of the 
property ?  All three classes have relationships of the same names.

 
 Have I set something up incorrectly or is this a bug?

its likely there's no test coverage for concrete (a use case I try to 
discourage people from using) + relationships on concrete (which was totally 
unsupported until very recently) + merge.

 
 (
 As an aside, instead of getting a 'NotImplementedError' when
 ConcreteInheritedProperty.merge() is called, I am getting TypeError:
 merge() takes exactly 6 arguments (8 given)

hence the deduction that there's no test coverage for this case.


 I think you need to update the MapperProperty interface's merge()
 definition from
 def merge(self, session, source, dest, load, _recursive):
 -
 def merge(self, session, source_state, source_dict, dest_state,
 dest_dict, load, _recursive):
 )
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 sqlalchemy group.
 To post to this group, send email to sqlalch...@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.
 

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@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.