sqlobject-cvs Mailing List for SQLObject (Page 135)
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
You can subscribe to this list here.
| 2003 |
Jan
|
Feb
|
Mar
(9) |
Apr
(74) |
May
(29) |
Jun
(16) |
Jul
(28) |
Aug
(10) |
Sep
(57) |
Oct
(9) |
Nov
(29) |
Dec
(12) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2004 |
Jan
(7) |
Feb
(14) |
Mar
(6) |
Apr
(3) |
May
(12) |
Jun
(34) |
Jul
(9) |
Aug
(29) |
Sep
(22) |
Oct
(2) |
Nov
(15) |
Dec
(52) |
| 2005 |
Jan
(47) |
Feb
(78) |
Mar
(14) |
Apr
(35) |
May
(33) |
Jun
(16) |
Jul
(26) |
Aug
(63) |
Sep
(40) |
Oct
(96) |
Nov
(96) |
Dec
(123) |
| 2006 |
Jan
(159) |
Feb
(144) |
Mar
(64) |
Apr
(31) |
May
(88) |
Jun
(48) |
Jul
(16) |
Aug
(64) |
Sep
(87) |
Oct
(92) |
Nov
(56) |
Dec
(76) |
| 2007 |
Jan
(94) |
Feb
(103) |
Mar
(126) |
Apr
(123) |
May
(85) |
Jun
(11) |
Jul
(130) |
Aug
(47) |
Sep
(65) |
Oct
(70) |
Nov
(12) |
Dec
(11) |
| 2008 |
Jan
(30) |
Feb
(55) |
Mar
(88) |
Apr
(20) |
May
(50) |
Jun
|
Jul
(38) |
Aug
(1) |
Sep
(9) |
Oct
(5) |
Nov
(6) |
Dec
(39) |
| 2009 |
Jan
(8) |
Feb
(16) |
Mar
(3) |
Apr
(33) |
May
(44) |
Jun
(1) |
Jul
(10) |
Aug
(33) |
Sep
(74) |
Oct
(22) |
Nov
|
Dec
(15) |
| 2010 |
Jan
(28) |
Feb
(22) |
Mar
(46) |
Apr
(29) |
May
(1) |
Jun
(1) |
Jul
(27) |
Aug
(8) |
Sep
(5) |
Oct
(33) |
Nov
(24) |
Dec
(41) |
| 2011 |
Jan
(4) |
Feb
(12) |
Mar
(35) |
Apr
(29) |
May
(19) |
Jun
(16) |
Jul
(32) |
Aug
(25) |
Sep
(5) |
Oct
(11) |
Nov
(21) |
Dec
(12) |
| 2012 |
Jan
(3) |
Feb
(4) |
Mar
(20) |
Apr
(4) |
May
(25) |
Jun
(13) |
Jul
|
Aug
|
Sep
(2) |
Oct
(25) |
Nov
(9) |
Dec
(1) |
| 2013 |
Jan
(6) |
Feb
(8) |
Mar
|
Apr
(10) |
May
(31) |
Jun
(7) |
Jul
(18) |
Aug
(33) |
Sep
(4) |
Oct
(16) |
Nov
|
Dec
(27) |
| 2014 |
Jan
(2) |
Feb
|
Mar
|
Apr
(11) |
May
(39) |
Jun
(8) |
Jul
(11) |
Aug
(4) |
Sep
|
Oct
(27) |
Nov
|
Dec
(71) |
| 2015 |
Jan
(17) |
Feb
(47) |
Mar
(33) |
Apr
|
May
|
Jun
(9) |
Jul
(7) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(8) |
| 2016 |
Jan
(4) |
Feb
(4) |
Mar
|
Apr
|
May
(12) |
Jun
(7) |
Jul
(9) |
Aug
(31) |
Sep
(8) |
Oct
(3) |
Nov
(15) |
Dec
(1) |
| 2017 |
Jan
(13) |
Feb
(7) |
Mar
(14) |
Apr
(8) |
May
(10) |
Jun
(4) |
Jul
(2) |
Aug
(1) |
Sep
|
Oct
(8) |
Nov
(4) |
Dec
(5) |
| 2018 |
Jan
(2) |
Feb
(8) |
Mar
|
Apr
(4) |
May
|
Jun
(6) |
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
(1) |
Dec
|
| 2019 |
Jan
(1) |
Feb
(16) |
Mar
(1) |
Apr
(3) |
May
(5) |
Jun
(1) |
Jul
|
Aug
|
Sep
(2) |
Oct
|
Nov
(1) |
Dec
(3) |
| 2020 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
(1) |
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
(2) |
Nov
|
Dec
(2) |
| 2021 |
Jan
|
Feb
(2) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
(1) |
Dec
|
| 2022 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(6) |
Oct
(1) |
Nov
(1) |
Dec
(4) |
| 2023 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
(3) |
Sep
(2) |
Oct
(2) |
Nov
(4) |
Dec
|
| 2024 |
Jan
|
Feb
(2) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
(9) |
| 2025 |
Jan
|
Feb
(4) |
Mar
(2) |
Apr
|
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
(2) |
Dec
(2) |
|
From: SourceForge.net <no...@so...> - 2006-02-20 15:31:57
|
Patches item #1432176, was opened at 2006-02-15 17:04 Message generated for change (Comment added) made by phd You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1432176&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None >Status: Closed >Resolution: Accepted Priority: 5 Submitted By: Björn Lindqvist (sonderblade) >Assigned to: Oleg Broytmann (phd) Summary: redundant methods in sqlobject -> foreign keys don't work Initial Comment: There are some redundant methods dealing with foreign key constraints that I think was introduced lately into SQLObject. They make foreign key constraints not work on mysql-databases. ---------------------------------------------------------------------- >Comment By: Oleg Broytmann (phd) Date: 2006-02-20 18:31 Message: Logged In: YES user_id=4799 Applied at the revision 1615. Please test and report if it helps. Thank you! ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1432176&group_id=74338 |
|
From: <sub...@co...> - 2006-02-20 15:31:03
|
Author: phd
Date: 2006-02-20 08:30:54 -0700 (Mon, 20 Feb 2006)
New Revision: 1615
Modified:
SQLObject/trunk/sqlobject/col.py
SQLObject/trunk/sqlobject/mysql/mysqlconnection.py
Log:
Applied the patch 1432176: redundant methods in sqlobject -> foreign keys don't work.
Modified: SQLObject/trunk/sqlobject/col.py
===================================================================
--- SQLObject/trunk/sqlobject/col.py 2006-02-20 15:25:08 UTC (rev 1614)
+++ SQLObject/trunk/sqlobject/col.py 2006-02-20 15:30:54 UTC (rev 1615)
@@ -781,37 +781,9 @@
'sTName': sTName})
return constraint
- def mysqlCreateReferenceConstraint(self):
- sTName = self.soClass.sqlmeta.table
- other = findClass(self.foreignKey, self.soClass.sqlmeta.registry)
- tName = other.sqlmeta.table
- idName = other.sqlmeta.idName
- if self.cascade is not None:
- if self.cascade == 'null':
- action = 'ON DELETE SET NULL'
- elif self.cascade:
- action = 'ON DELETE CASCADE'
- else:
- action = 'ON DELETE RESTRICT'
- else:
- action = ''
- constraint = ('ALTER TABLE %(sTName)s ADD CONSTRAINT %(sTName)s_%(colName)s_to_%(tName)s '
- 'FOREIGN KEY (%(colName)s) '
- 'REFERENCES %(tName)s (%(idName)s) '
- '%(action)s' %
- {'tName': tName,
- 'colName': self.dbName,
- 'idName': idName,
- 'action': action,
- 'sTName': sTName})
- return constraint
-
def mysqlCreateSQL(self):
return SOKeyCol.mysqlCreateSQL(self)
- def mysqlCreateReferenceConstraint(self):
- return None
-
def sybaseCreateSQL(self):
sql = SOKeyCol.sybaseCreateSQL(self)
other = findClass(self.foreignKey)
Modified: SQLObject/trunk/sqlobject/mysql/mysqlconnection.py
===================================================================
--- SQLObject/trunk/sqlobject/mysql/mysqlconnection.py 2006-02-20 15:25:08 UTC (rev 1614)
+++ SQLObject/trunk/sqlobject/mysql/mysqlconnection.py 2006-02-20 15:30:54 UTC (rev 1615)
@@ -104,15 +104,9 @@
def createColumn(self, soClass, col):
return col.mysqlCreateSQL()
- def createReferenceConstraint(self, soClass, col):
- return col.mysqlCreateReferenceConstraint()
-
def createIndexSQL(self, soClass, index):
return index.mysqlCreateIndexSQL(soClass)
- def createReferenceConstraint(self, soClass, col):
- return col.mysqlCreateReferenceConstraint()
-
def createIDColumn(self, soClass):
if soClass.sqlmeta.idType == str:
return '%s TEXT PRIMARY KEY' % soClass.sqlmeta.idName
|
|
From: <sub...@co...> - 2006-02-20 15:25:26
|
Author: phd
Date: 2006-02-20 08:25:08 -0700 (Mon, 20 Feb 2006)
New Revision: 1614
Modified:
home/phd/SQLObject/paramstyles/sqlobject/col.py
home/phd/SQLObject/paramstyles/sqlobject/tests/test_foreignKey.py
Log:
Merged patches from the revisions 1611:1613 from the trunk
Modified: home/phd/SQLObject/paramstyles/sqlobject/col.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/col.py 2006-02-20 15:22:14 UTC (rev 1613)
+++ home/phd/SQLObject/paramstyles/sqlobject/col.py 2006-02-20 15:25:08 UTC (rev 1614)
@@ -538,6 +538,8 @@
return None
if isinstance(value, unicode):
return value
+ if isinstance(value, array_type): # MySQL
+ return unicode(value.tostring(), self.db_encoding)
return unicode(value, self.db_encoding)
def from_python(self, value, state):
Modified: home/phd/SQLObject/paramstyles/sqlobject/tests/test_foreignKey.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/tests/test_foreignKey.py 2006-02-20 15:22:14 UTC (rev 1613)
+++ home/phd/SQLObject/paramstyles/sqlobject/tests/test_foreignKey.py 2006-02-20 15:25:08 UTC (rev 1614)
@@ -38,5 +38,7 @@
assert s[0]==w2
def test2():
+ TestWorkKey._connection = getConnection()
+ InstalledTestDatabase.drop(TestWorkKey)
setupClass([TestComposerKey, TestWorkKey2], force=True)
TestWorkKey2.sqlmeta.addColumn(ForeignKey('TestComposerKey'), changeSchema=True)
|
|
From: SourceForge.net <no...@so...> - 2006-02-20 15:22:54
|
Patches item #1432091, was opened at 2006-02-15 14:15 Message generated for change (Comment added) made by phd You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1432091&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None >Status: Closed >Resolution: Accepted Priority: 5 Submitted By: Etienne Posthumus (epoz) >Assigned to: Oleg Broytmann (phd) Summary: Handling array.array TEXT from MySQL results Initial Comment: For the UnicodeCol TEXT fields in a MySQL database, the results returned are not Strings but array.array. This patch to col.py enables the conversion to Unicode values. ---------------------------------------------------------------------- >Comment By: Oleg Broytmann (phd) Date: 2006-02-20 18:22 Message: Logged In: YES user_id=4799 Applied to the trunk in the revision 1612, and to the 0.7-branch in the rev. 1613. Thank you! ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1432091&group_id=74338 |
|
From: <sub...@co...> - 2006-02-20 15:22:20
|
Author: phd
Date: 2006-02-20 08:22:14 -0700 (Mon, 20 Feb 2006)
New Revision: 1613
Modified:
SQLObject/branches/0.7-bugfix/sqlobject/col.py
Log:
Applied the patch 1432091: handling array.array TEXT from MySQL results.
Modified: SQLObject/branches/0.7-bugfix/sqlobject/col.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/col.py 2006-02-20 15:21:39 UTC (rev 1612)
+++ SQLObject/branches/0.7-bugfix/sqlobject/col.py 2006-02-20 15:22:14 UTC (rev 1613)
@@ -535,6 +535,8 @@
return None
if isinstance(value, unicode):
return value
+ if isinstance(value, array_type): # MySQL
+ return unicode(value.tostring(), self.db_encoding)
return unicode(value, self.db_encoding)
def from_python(self, value, state):
|
|
From: <sub...@co...> - 2006-02-20 15:21:48
|
Author: phd
Date: 2006-02-20 08:21:39 -0700 (Mon, 20 Feb 2006)
New Revision: 1612
Modified:
SQLObject/trunk/sqlobject/col.py
SQLObject/trunk/sqlobject/tests/test_foreignKey.py
Log:
Applied the patch 1432091: handling array.array TEXT from MySQL results.
Modified: SQLObject/trunk/sqlobject/col.py
===================================================================
--- SQLObject/trunk/sqlobject/col.py 2006-02-19 04:13:55 UTC (rev 1611)
+++ SQLObject/trunk/sqlobject/col.py 2006-02-20 15:21:39 UTC (rev 1612)
@@ -538,6 +538,8 @@
return None
if isinstance(value, unicode):
return value
+ if isinstance(value, array_type): # MySQL
+ return unicode(value.tostring(), self.db_encoding)
return unicode(value, self.db_encoding)
def from_python(self, value, state):
Modified: SQLObject/trunk/sqlobject/tests/test_foreignKey.py
===================================================================
--- SQLObject/trunk/sqlobject/tests/test_foreignKey.py 2006-02-19 04:13:55 UTC (rev 1611)
+++ SQLObject/trunk/sqlobject/tests/test_foreignKey.py 2006-02-20 15:21:39 UTC (rev 1612)
@@ -39,7 +39,7 @@
assert s[0]==w2
def test2():
- TestWorkKey ._connection = getConnection()
+ TestWorkKey._connection = getConnection()
InstalledTestDatabase.drop(TestWorkKey)
setupClass([TestComposerKey, TestWorkKey2], force=True)
TestWorkKey2.sqlmeta.addColumn(ForeignKey('TestComposerKey'), changeSchema=True)
|
|
From: SourceForge.net <no...@so...> - 2006-02-20 15:05:10
|
Patches item #1432078, was opened at 2006-02-15 13:56 Message generated for change (Comment added) made by phd You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1432078&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Submitted By: Etienne Posthumus (epoz) >Assigned to: Oleg Broytmann (phd) Summary: Add DISTINCT to sqlbuilder.py Select Initial Comment: When using SQLBuilder do build database-independent queries, I would like to do DISTINCT queries. This already exists in normal SQLObject ClassName.select, but not in the builder. This tiny patch adds it. ---------------------------------------------------------------------- >Comment By: Oleg Broytmann (phd) Date: 2006-02-20 18:05 Message: Logged In: YES user_id=4799 First, I would like to ask you to avoid copy/paste programming. (-: Please refactor your code - there is duplicate code in 'if' and 'else' branches. I think you can just conditionally insert "DISTINCT" or '' (an empty string). Second, I'd like to ask you to add a test. May be create test_sqlbuilder.py, and test assert str(Select(...)) = "SELECT..." Something like this... Third, it would be very kind of you if you add a few strings about Select() to docs/SQLBuilder.txt - now when you understand sqlbuilder and Select(). Thank you in advance! ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1432078&group_id=74338 |
|
From: SourceForge.net <no...@so...> - 2006-02-20 14:54:06
|
Patches item #1353728, was opened at 2005-11-11 10:20 Message generated for change (Comment added) made by phd You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1353728&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Submitted By: Pau Aliagas (linux4u) Assigned to: Oleg Broytmann (phd) Summary: define foreign keys in Style Initial Comment: I don't like to use attrID all along the code to access related tables, I want to be able use the nomeclature I like taking advantage of the nice Style idea. This is especially true when you create RelatedJoins when you use a nomeclature like I do (table.id_table), but it's the same for all the nomeclatures you can imagine. In styles.py it warns: def instanceAttrToIDAttr(self, attr): # @@: Right now, because of how names are created for foreign # keys, you can't really change this style. return attr + "ID" With this patch you can define how you want the foreign keys generated, they won't be mandatorily generated as attrID. Example: class LongStyle(Style): """ This style is derived from Style, that does not do any translation, but constructs the table ids like id_table. """ def instanceAttrToIDAttr(self, attr): return "id_" + attr def tableReference(self, table): # str.rsplit is python 2.4+ only if version_info >= (2, 4): return "id_" + table.rsplit(".", 1)[-1] else: return "id_" + rsplit(table, ".", 1)[-1] class mm_server(SQLObject): class sqlmeta: table = "smsarena.mm_server" style = LongStyle(longID = True) _connection = conn_smsarena server = StringCol(alternateID = True, varchar = True, length = 255, alternateMethodName = "by_server") tz = StringCol(length = 20, default = 'CET', notNone = True) conutry_code = StringCol(length = 2, varchar = False, default = '', notNone = True) # until now I had to do this # mm_server_aliases = SQLMultipleJoin("mm_server_alias", joinColumn = "mm_serverID", orderBy = "server") # now it's perfect! mm_server_aliases = SQLMultipleJoin("mm_server_alias", orderBy = "server") class mm_server_alias(SQLObject): class sqlmeta: table = "smsarena.mm_server_alias" style = LongStyle(longID = True) _connection = conn_smsarena # until now I had to do this # mm_server = ForeignKey("mm_server", dbName = "id_mm_server") mm_server = ForeignKey("mm_server") server = StringCol(alternateID = True, varchar = True, length = 255, alternateMethodName = "by_server") I hope it's clear :) Pau ---------------------------------------------------------------------- >Comment By: Oleg Broytmann (phd) Date: 2006-02-20 17:54 Message: Logged In: YES user_id=4799 Doesn't work in 0.7. First, you've mixed tabs and spaces and used the name 's' instead of 'attr'. These two are easy to fix. But unpatched test_auto.py and test_auto_old.py fail: def test_dynamicJoin(self): col = KeyCol('oldPersonID', foreignKey='OldPerson') OldPhone.addColumn(col, changeSchema=True) join = MultipleJoin('OldPhone') OldPerson.addJoin(join) for phone in OldPhone.select('all'): if phone.phone.startswith('555'): phone.oldPerson = OldPerson.selectBy(name='tim')[0] else: phone.oldPerson = OldPerson.selectBy(name='bob')[0] l = [p.phone for p in OldPerson.selectBy(name='tim')[0].oldPhones] l.sort() E assert l == ['555-394-2930', '555-555-5555'] > assert [] == ['555-394-2930', '555-555-5555'] You can work on it further. Or you can abandon it and it will not be applied in 0.7 branch. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 20:11 Message: Logged In: YES user_id=140558 Ok, this is the patch for keeping the exact behaviour in 0.7. For 0.7, as you say, don't patch the tests. Please do not apply it to 0.8 :) ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 19:58 Message: Logged In: YES user_id=4799 Please do. I reopened the patch. Instead of one-line patch for Style IWBN to make a smaller (than the original) patch that avoids patching .addColumn() in tests, isn't it? ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 19:39 Message: Logged In: YES user_id=140558 This can be solve with a onliner in default style: if not name.endswith("ID")... IMHO doing addColumn(fieldID, ForeignKey..) is a mistake You should do addColumn(field, ForeignKey..) and style takes care of it. If you want I can submit this oneliner for 0.7 only and you reconsider ading it to 0.7. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 19:29 Message: Logged In: YES user_id=4799 Even that's a big change, too big for 0.7 bugfix. Don't hesitate to post patches or at least bug reports for other issues. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 19:12 Message: Logged In: YES user_id=140558 Answering your concerns about the API... The only change is the one I have explained when using addColumn(fieldID, ForeignKey..). If you put ID, the current default style rules would add it too, so you'd get fieldIDID. We could change the style rules and look at this case, but I think that the current behaviour (as it is now with the patch) is completly orthogonal and always acts the same way, no black magic required. For the rest this is a HUGE addition!! You don't need to worry anymore about namning styles, nothing is written in stone. the ID thing was everywhere in the code Combined with the other patch (select using the object, not the id), you can almost always avoid referring directly to foreign field names. I really feel much more comfortable with these changes applied, seeign fieldID in the code maed me feel that something was not competely right. Avoiding it makes the code look beautiful. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 19:06 Message: Logged In: YES user_id=4799 SUM() should return whtaver the DB returns. I think summing an INT column returns an int, summing a FLOAT column returns a float. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 18:59 Message: Logged In: YES user_id=140558 Ok, another test mistery solved: This is the culprit that test_SQLMultipleJoin.py fails: assert str(hibrid.fightersAsSResult.sum('power')) == '23' In pgsql hibrid.fightersAsSResult.sum('power') returns 23. In sqlite-3.1.2 and mysql-4.1 it returns 23.0. So we should either fix the test or the sum function. Fixing the test could be as easy as casting the float to int: assert str(int(hibrid.fightersAsSResult.sum('power'))) == '23' but I'mn not sure if this would hide a bug. Should sum return float or int? ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 18:55 Message: Logged In: YES user_id=4799 Yes, it works finally! Applied in the revision 1607. Thank you for the job! How much does it change the API? Does it have meaning to be applied to 0.7 branch? I actually applied it and it passed all tests, but I don't want to break API for 0.7.1. Will all old programs work? ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 18:49 Message: Logged In: YES user_id=140558 After fixing my patch (I'm sure it works now!!) I'm reviewing the tests that fail. See the attached file "failed tests 2006-01-17 version 1" for the tests an the detailed explanations. In summary: test_ForeignKey.py: you know about it, it fails in all the databases test_SQLMultipleJoin.py: I don't see why it fails, it fails in sqlite and mysql, not in pgsql * sqlite * my problem is that sqlite-3.1.2 does not support alter tabble ad column, so no problem. * mysql * test_datetime.py ---------------- to_python does not seem to work as expected. test_enum.py ------------ BLOB/TEXT column indexes require length in mysql I hope that this makes clear the current status. If you accept the current patch, maybe we could open another ticket with the current bugs in mysql and sqlite, as these are clearly separate issues. Thanks ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 16:26 Message: Logged In: YES user_id=140558 I've fixed the problems with addColumns and delColum, now it passes the tests (not the ones that fail I do not why). I've fixed the tests too: I think we should NOT add the columns with ID at the end as the style add it for you. Otherwise I should modify the sytle functions to conditionally check if they end in ID.... I don't think that it is ok, if we want that, we define anthjer style that removes double ID at the end. This is internal to the style and so should be kept. Hope it's ok now :) ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 16:01 Message: Logged In: YES user_id=140558 These are my versions (ignore my comment in the other patch ticket, my misake): mysql-4.1.16-1.FC4.1 postgresql-8.0.7-1.FC4.1 python-psycopg-1.1.21-1.fc4 python-sqlite-1.1.6-1 sqlite-3.1.2-3 ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 15:38 Message: Logged In: YES user_id=4799 Except for the problem i test_ForeignKey.py that I know about... others look pretty strange. Let look at the environment. What DB versions? MySQL, PgSQL, SQLite? Drivers versions? MySQLdb, psycopg, PySQLite? MyPostgres is 7.4, psycopg 1.1.21 and 2.0b5. PySQLite 1.1.7 and 2.1.3. A week ago I upgarded to SQLite 3.3.3 and PySQLite 2.1.3; that eliminated some minor problems with patches I have had with SQLIte 2.8.0 and PySQLite 2.1.0. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 15:11 Message: Logged In: YES user_id=140558 Ok, plain SQLObject from SVN now, no patch. There are tests that fail for me in current SQLObject in mysql, postgres and sqlite. I attach them all. This is a fully updated Fedora 4. I've made the tests in mysql and there are some thet do not pass. I enclose the results and a file where I comment why the fail and a possible solution. The tests that fail in postgres and sqlite are the ones I've already reported (mnore or less). Any help? ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 12:22 Message: Logged In: YES user_id=4799 No, the latest SQLObject passes all tests (how would I commit your other patch if a test fail?) except for minor glitch in test_ForeignKey.py which I'm going to resolve RSN. test_auto.py certainly pass. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 12:13 Message: Logged In: YES user_id=140558 I've run the test with the latest SQLObject (no extra patches) and the tests fail too, at least they fail when I run them. As I explained before, there's something wrong when adding columns to sqlite, it fails and all the tests that depend on the added columns fail too. Does it happen to you too? ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-16 18:16 Message: Logged In: YES user_id=4799 These tests fail in both Postgres and SQLite. Two major backends (of 3) for SQLObject. If the problem is in tests you can patch tests, too... test_auto.py: def test_dynamicJoin(self): col = KeyCol('personID', foreignKey='Person') Phone.sqlmeta.addColumn(col, changeSchema=True) join = MultipleJoin('Phone') Person.sqlmeta.addJoin(join) for phone in Phone.select('all'): if phone.phone.startswith('555'): phone.person = Person.selectBy(name='tim')[0] else: phone.person = Person.selectBy(name='bob')[0] > l = [p.phone for p in Person.selectBy(name='tim')[0].phones] [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/test_auto.py:59] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > [failure to get at sourcelines from <TracebackEntry /home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/<string>:1>] [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/<string>:1] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def performJoin(self, inst): ids = inst._connection._SO_selectJoin( self.otherClass, self.joinColumn, > inst.id) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/joins.py:144] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _SO_selectJoin(self, soClass, column, value): return self.queryAll("SELECT %s FROM %s WHERE %s = %s" % (soClass.sqlmeta.idName, soClass.sqlmeta.table, column, > self.sqlrepr(value))) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:652] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def queryAll(self, s): > return self._runWithConnection(self._queryAll, s) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:327] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _runWithConnection(self, meth, *args): conn = self.getConnection() try: > val = meth(conn, *args) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:228] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _queryAll(self, conn, s): if self.debug: self.printDebug(conn, s, 'QueryAll') c = conn.cursor() > self._executeRetry(conn, c, s) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:320] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _executeRetry(self, conn, cursor, query): if self.debug: self.printDebug(conn, query, 'QueryR') E return cursor.execute(query) > OperationalError: no such column: person_id [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:306] - - - - - - - - - - - test_dynamicJoin: recorded stdout - - - - - - - - - - - 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/Query : DELETE FROM person 1/QueryR : DELETE FROM person 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/Query : DELETE FROM phone 1/QueryR : DELETE FROM phone 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('jane') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 1 1/QueryR : SELECT name_col FROM person WHERE id = 1 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('tim') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 2 1/QueryR : SELECT name_col FROM person WHERE id = 2 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('bob') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 3 1/QueryR : SELECT name_col FROM person WHERE id = 3 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('jake') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 4 1/QueryR : SELECT name_col FROM person WHERE id = 4 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('555-555-5555') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 1 1/QueryR : SELECT phone FROM phone WHERE id = 1 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('555-394-2930') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 2 1/QueryR : SELECT phone FROM phone WHERE id = 2 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('444-382-4854') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 3 1/QueryR : SELECT phone FROM phone WHERE id = 3 1/COMMIT : auto 1/Query : ALTER TABLE phone ADD COLUMN person_i_d_id INT 1/QueryR : ALTER TABLE phone ADD COLUMN person_i_d_id INT 1/COMMIT : auto 1/Select : SELECT phone.id, phone.phone, phone.person_i_d_id FROM phone WHERE 1 = 1 ORDER BY phone 1/QueryR : SELECT phone.id, phone.phone, phone.person_i_d_id FROM phone WHERE 1 = 1 ORDER BY phone 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'bob' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'bob' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/QueryAll: SELECT id FROM phone WHERE person_id = 2 1/QueryR : SELECT id FROM phone WHERE person_id = 2 1/COMMIT : auto ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-15 18:54 Message: Logged In: YES user_id=140558 Ok, here I go again. I've fixed a small bug: the name of the field was not porperly set when using Key(foreignKey... instead of ForeignKey. This fixes test_basic. And I think that there is nothing else to fix, I'm probably wrong, but I'll explain it hera. test_auto_old.py... FAIL test_auto.py... FAIL test_foreignKey.py... FAIL These tests fail because sqlite is failing when adding columns. In mysql it does not fail. I do not think it's this patch fault. And finally: test_SQLMultipleJoin.py... FAIL E assert str(hibrid.fightersAsSResult.sum('power')) == '23' > assert '23.0' == '23' + where '23.0' = str(23.0) + where 23.0 = <Race 3 name="'hibrid (human wi...'">.fightersAsSResult.sum('power') Again this is an error in the test. Please let me know if it can go in now :) If you can have a quick look at it better, it takes time to restart ths tests, I'd rather do it before I move on to another thing. Thanks Pau ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-14 12:05 Message: Logged In: YES user_id=140558 Oleg, I've posted to the list because I run the tests and pass. I'm sure I'm doing something wrong but I don't see what. I lost more than 3 hours yesterday just trying to run te tests :( I printed things in dbtest.py and say that TESTDB did not change anything. I chenged manually conftest.py because I ahd a message that yoiu need sqlite2 for memory databases, but still I'm not sure everything works becasue I pass al the tests. Can you help me, I want to close this patch soon and move to other improvements but this is being much more difficult than it should. Thanks a lot Pau ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-09 19:42 Message: Logged In: YES user_id=140558 I'm very busy but again will try to find some time to fix it. I'm using it every day without a glitch, even using the clause attributes like in the Complex example (new type of joins *toMany). I'll update it to latest SVN just in case this is the problem, I did it with that day's current. Please do not close it, I really intend to pass the tests, I'm already using it. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-09 19:11 Message: Logged In: YES user_id=4799 test_auto.py, for example fails: def test_dynamicJoin(self): col = KeyCol('personID', foreignKey='Person') Phone.sqlmeta.addColumn(col, changeSchema=True) join = MultipleJoin('Phone') Person.sqlmeta.addJoin(join) for phone in Phone.select('all'): if phone.phone.startswith('555'): phone.person = Person.selectBy(name='tim')[0] else: phone.person = Person.selectBy(name='bob')[0] l = [p.phone for p in Person.selectBy(name='tim')[0].phones] l.sort() E assert l == ['555-394-2930', '555-555-5555'] > assert [] == ['555-394-2930', '555-555-5555'] [sqlobject/tests/test_auto.py:61] ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-30 21:10 Message: Logged In: YES user_id=140558 I'll recheck it, it really passed all the tests applied to the latest svn. I tell you something tomorrow. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-30 21:07 Message: Logged In: YES user_id=140558 I'll recheck it, it really passed all the tests applied to the latest svn. I tell you something tomorrow. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-30 20:57 Message: Logged In: YES user_id=4799 test_auto.py, test_auto_old.py and test_basic.py failed. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-18 19:04 Message: Logged In: YES user_id=140558 This is the final patch against latest svn, it includes everything in one single patch. It passes the tests. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-18 16:17 Message: Logged In: YES user_id=140558 Ok, I have taken my time to understand pydist, test, etc, and here I am back with the working solution :) Now the resulting SQLobject passes all the tests. I attach an incremental patch so that you can see more clearly the changes done to fix the previous one. I've needed a new method in the Style class, instanceIDAttrToAttr, that is the complementary to the already known instanceAttrToIDAttr. If you need to transform back and forth field names, you need them both. I haven't tried to port it to the latest svn yet, this is against the same release than the first patch, but it should apply more or less clearly as this are very isolated areas in the code. When I do it I'll post it here. Sorry for the delay, it has not been easy for me to understand more deeply the code and, even less, to know how the tests work :) ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-03 15:18 Message: Logged In: YES user_id=140558 It fails because the test is not right, it still has the ID postfix hardcoded. My fault, I did no send a patch for tests. This is the piece that fails: # Select by usual way s = TestWorkKey.selectBy(composerID=c.id, title='Symphony No. 9') I have not looked at tests until now, but it looks like there should be tests for the different provides styles, in this case, if you accept the patch, at least a test for the LongStyle provided and for the current naming styles. I'll try to cook up something, but it can take a little time. Any guidelines will be appreciated (I've just read the docs ;) ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-03 14:23 Message: Logged In: YES user_id=4799 test_selectBy_foreignKey.py fails: def test1(): setupClass([TestComposerKey, TestWorkKey]) c = TestComposerKey(name='Mahler, Gustav') > w1 = TestWorkKey(composer=c, title='Symphony No. 9') [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/tests/test_selectBy_foreignKey.py:19] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def __init__(self, **kw): # The get() classmethod/constructor uses a magic keyword # argument when it wants an empty object, fetched from the # database. So we have nothing more to do in that case: if kw.has_key('_SO_fetch_no_create'): return post_funcs = [] self.sqlmeta.send(events.RowCreateSignal, kw, post_funcs) # Pass the connection object along if we were given one. if kw.has_key('connection'): self._connection = kw['connection'] self.sqlmeta._perConnection = True del kw['connection'] self._SO_writeLock = threading.Lock() if kw.has_key('id'): id = self.sqlmeta.idType(kw['id']) del kw['id'] else: id = None > self._create(id, **kw) [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/main.py:1210] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _create(self, id, **kw): self.sqlmeta._creating = True self._SO_createValues = {} self._SO_validatorState = SQLObjectState(self) # First we do a little fix-up on the keywords we were # passed: for column in self.sqlmeta.columnList: # Then we check if the column wasn't passed in, and # if not we try to get the default. if not kw.has_key(column.name) and not kw.has_key(column.foreignName): default = column.default # If we don't get it, it's an error: if default is NoDefault: E raise TypeError, "%s() did not get expected keyword argument %s" % (self.__class__.__name__, column.name) > TypeError: TestWorkKey() did not get expected keyword argument composerID [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/main.py:1231] - - - - - - - - - - - - - test1: recorded stdout - - - - - - - - - - - - - - 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/Query : CREATE TABLE test_composer_key ( id SERIAL PRIMARY KEY, name TEXT ) 1/QueryR : CREATE TABLE test_composer_key ( id SERIAL PRIMARY KEY, name TEXT ) 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/Query : CREATE TABLE test_work_key ( work_id SERIAL PRIMARY KEY, composer_id INT, title TEXT ) 1/QueryR : CREATE TABLE test_work_key ( work_id SERIAL PRIMARY KEY, composer_id INT, title TEXT ) 1/COMMIT : auto 1/Query : ALTER TABLE test_work_key ADD CONSTRAINT composer_id_exists FOREIGN KEY (composer_id) REFERENCES test_composer_key (id) 1/QueryR : ALTER TABLE test_work_key ADD CONSTRAINT composer_id_exists FOREIGN KEY (composer_id) REFERENCES test_composer_key (id) 1/COMMIT : auto 1/QueryIns: INSERT INTO test_composer_key (id, name) VALUES (1, 'Mahler, Gustav') 1/COMMIT : auto 1/QueryOne: SELECT name FROM test_composer_key WHERE id = 1 1/QueryR : SELECT name FROM test_composer_key WHERE id = 1 1/COMMIT : auto ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1353728&group_id=74338 |
|
From: <sub...@co...> - 2006-02-19 04:14:00
|
Author: ianb Date: 2006-02-18 21:13:55 -0700 (Sat, 18 Feb 2006) New Revision: 1611 Modified: SQLObject/docs/index.comments.txt Log: in page: http://pythonpaste.org/ by: Adrian H. Add comment Modified: SQLObject/docs/index.comments.txt =================================================================== --- SQLObject/docs/index.comments.txt 2006-02-17 21:59:14 UTC (rev 1610) +++ SQLObject/docs/index.comments.txt 2006-02-19 04:13:55 UTC (rev 1611) @@ -22,3 +22,11 @@ username: MB Auch an unterschiedlichen Stellen geht das +==== $(start) +++ c +---------------------------------------- +date: 2006-02-18T21:13:55 +id: 4 +ip: 216.80.121.210 +username: Adrian H. + +Just spamming this page with another test! :) |
|
From: SourceForge.net <no...@so...> - 2006-02-17 17:11:42
|
Patches item #1353728, was opened at 2005-11-11 08:20 Message generated for change (Comment added) made by linux4u You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1353728&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Submitted By: Pau Aliagas (linux4u) Assigned to: Oleg Broytmann (phd) Summary: define foreign keys in Style Initial Comment: I don't like to use attrID all along the code to access related tables, I want to be able use the nomeclature I like taking advantage of the nice Style idea. This is especially true when you create RelatedJoins when you use a nomeclature like I do (table.id_table), but it's the same for all the nomeclatures you can imagine. In styles.py it warns: def instanceAttrToIDAttr(self, attr): # @@: Right now, because of how names are created for foreign # keys, you can't really change this style. return attr + "ID" With this patch you can define how you want the foreign keys generated, they won't be mandatorily generated as attrID. Example: class LongStyle(Style): """ This style is derived from Style, that does not do any translation, but constructs the table ids like id_table. """ def instanceAttrToIDAttr(self, attr): return "id_" + attr def tableReference(self, table): # str.rsplit is python 2.4+ only if version_info >= (2, 4): return "id_" + table.rsplit(".", 1)[-1] else: return "id_" + rsplit(table, ".", 1)[-1] class mm_server(SQLObject): class sqlmeta: table = "smsarena.mm_server" style = LongStyle(longID = True) _connection = conn_smsarena server = StringCol(alternateID = True, varchar = True, length = 255, alternateMethodName = "by_server") tz = StringCol(length = 20, default = 'CET', notNone = True) conutry_code = StringCol(length = 2, varchar = False, default = '', notNone = True) # until now I had to do this # mm_server_aliases = SQLMultipleJoin("mm_server_alias", joinColumn = "mm_serverID", orderBy = "server") # now it's perfect! mm_server_aliases = SQLMultipleJoin("mm_server_alias", orderBy = "server") class mm_server_alias(SQLObject): class sqlmeta: table = "smsarena.mm_server_alias" style = LongStyle(longID = True) _connection = conn_smsarena # until now I had to do this # mm_server = ForeignKey("mm_server", dbName = "id_mm_server") mm_server = ForeignKey("mm_server") server = StringCol(alternateID = True, varchar = True, length = 255, alternateMethodName = "by_server") I hope it's clear :) Pau ---------------------------------------------------------------------- >Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 18:11 Message: Logged In: YES user_id=140558 Ok, this is the patch for keeping the exact behaviour in 0.7. For 0.7, as you say, don't patch the tests. Please do not apply it to 0.8 :) ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 17:58 Message: Logged In: YES user_id=4799 Please do. I reopened the patch. Instead of one-line patch for Style IWBN to make a smaller (than the original) patch that avoids patching .addColumn() in tests, isn't it? ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 17:39 Message: Logged In: YES user_id=140558 This can be solve with a onliner in default style: if not name.endswith("ID")... IMHO doing addColumn(fieldID, ForeignKey..) is a mistake You should do addColumn(field, ForeignKey..) and style takes care of it. If you want I can submit this oneliner for 0.7 only and you reconsider ading it to 0.7. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 17:29 Message: Logged In: YES user_id=4799 Even that's a big change, too big for 0.7 bugfix. Don't hesitate to post patches or at least bug reports for other issues. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 17:12 Message: Logged In: YES user_id=140558 Answering your concerns about the API... The only change is the one I have explained when using addColumn(fieldID, ForeignKey..). If you put ID, the current default style rules would add it too, so you'd get fieldIDID. We could change the style rules and look at this case, but I think that the current behaviour (as it is now with the patch) is completly orthogonal and always acts the same way, no black magic required. For the rest this is a HUGE addition!! You don't need to worry anymore about namning styles, nothing is written in stone. the ID thing was everywhere in the code Combined with the other patch (select using the object, not the id), you can almost always avoid referring directly to foreign field names. I really feel much more comfortable with these changes applied, seeign fieldID in the code maed me feel that something was not competely right. Avoiding it makes the code look beautiful. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 17:06 Message: Logged In: YES user_id=4799 SUM() should return whtaver the DB returns. I think summing an INT column returns an int, summing a FLOAT column returns a float. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 16:59 Message: Logged In: YES user_id=140558 Ok, another test mistery solved: This is the culprit that test_SQLMultipleJoin.py fails: assert str(hibrid.fightersAsSResult.sum('power')) == '23' In pgsql hibrid.fightersAsSResult.sum('power') returns 23. In sqlite-3.1.2 and mysql-4.1 it returns 23.0. So we should either fix the test or the sum function. Fixing the test could be as easy as casting the float to int: assert str(int(hibrid.fightersAsSResult.sum('power'))) == '23' but I'mn not sure if this would hide a bug. Should sum return float or int? ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 16:55 Message: Logged In: YES user_id=4799 Yes, it works finally! Applied in the revision 1607. Thank you for the job! How much does it change the API? Does it have meaning to be applied to 0.7 branch? I actually applied it and it passed all tests, but I don't want to break API for 0.7.1. Will all old programs work? ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 16:49 Message: Logged In: YES user_id=140558 After fixing my patch (I'm sure it works now!!) I'm reviewing the tests that fail. See the attached file "failed tests 2006-01-17 version 1" for the tests an the detailed explanations. In summary: test_ForeignKey.py: you know about it, it fails in all the databases test_SQLMultipleJoin.py: I don't see why it fails, it fails in sqlite and mysql, not in pgsql * sqlite * my problem is that sqlite-3.1.2 does not support alter tabble ad column, so no problem. * mysql * test_datetime.py ---------------- to_python does not seem to work as expected. test_enum.py ------------ BLOB/TEXT column indexes require length in mysql I hope that this makes clear the current status. If you accept the current patch, maybe we could open another ticket with the current bugs in mysql and sqlite, as these are clearly separate issues. Thanks ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 14:26 Message: Logged In: YES user_id=140558 I've fixed the problems with addColumns and delColum, now it passes the tests (not the ones that fail I do not why). I've fixed the tests too: I think we should NOT add the columns with ID at the end as the style add it for you. Otherwise I should modify the sytle functions to conditionally check if they end in ID.... I don't think that it is ok, if we want that, we define anthjer style that removes double ID at the end. This is internal to the style and so should be kept. Hope it's ok now :) ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 14:01 Message: Logged In: YES user_id=140558 These are my versions (ignore my comment in the other patch ticket, my misake): mysql-4.1.16-1.FC4.1 postgresql-8.0.7-1.FC4.1 python-psycopg-1.1.21-1.fc4 python-sqlite-1.1.6-1 sqlite-3.1.2-3 ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 13:38 Message: Logged In: YES user_id=4799 Except for the problem i test_ForeignKey.py that I know about... others look pretty strange. Let look at the environment. What DB versions? MySQL, PgSQL, SQLite? Drivers versions? MySQLdb, psycopg, PySQLite? MyPostgres is 7.4, psycopg 1.1.21 and 2.0b5. PySQLite 1.1.7 and 2.1.3. A week ago I upgarded to SQLite 3.3.3 and PySQLite 2.1.3; that eliminated some minor problems with patches I have had with SQLIte 2.8.0 and PySQLite 2.1.0. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 13:11 Message: Logged In: YES user_id=140558 Ok, plain SQLObject from SVN now, no patch. There are tests that fail for me in current SQLObject in mysql, postgres and sqlite. I attach them all. This is a fully updated Fedora 4. I've made the tests in mysql and there are some thet do not pass. I enclose the results and a file where I comment why the fail and a possible solution. The tests that fail in postgres and sqlite are the ones I've already reported (mnore or less). Any help? ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 10:22 Message: Logged In: YES user_id=4799 No, the latest SQLObject passes all tests (how would I commit your other patch if a test fail?) except for minor glitch in test_ForeignKey.py which I'm going to resolve RSN. test_auto.py certainly pass. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 10:13 Message: Logged In: YES user_id=140558 I've run the test with the latest SQLObject (no extra patches) and the tests fail too, at least they fail when I run them. As I explained before, there's something wrong when adding columns to sqlite, it fails and all the tests that depend on the added columns fail too. Does it happen to you too? ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-16 16:16 Message: Logged In: YES user_id=4799 These tests fail in both Postgres and SQLite. Two major backends (of 3) for SQLObject. If the problem is in tests you can patch tests, too... test_auto.py: def test_dynamicJoin(self): col = KeyCol('personID', foreignKey='Person') Phone.sqlmeta.addColumn(col, changeSchema=True) join = MultipleJoin('Phone') Person.sqlmeta.addJoin(join) for phone in Phone.select('all'): if phone.phone.startswith('555'): phone.person = Person.selectBy(name='tim')[0] else: phone.person = Person.selectBy(name='bob')[0] > l = [p.phone for p in Person.selectBy(name='tim')[0].phones] [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/test_auto.py:59] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > [failure to get at sourcelines from <TracebackEntry /home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/<string>:1>] [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/<string>:1] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def performJoin(self, inst): ids = inst._connection._SO_selectJoin( self.otherClass, self.joinColumn, > inst.id) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/joins.py:144] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _SO_selectJoin(self, soClass, column, value): return self.queryAll("SELECT %s FROM %s WHERE %s = %s" % (soClass.sqlmeta.idName, soClass.sqlmeta.table, column, > self.sqlrepr(value))) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:652] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def queryAll(self, s): > return self._runWithConnection(self._queryAll, s) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:327] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _runWithConnection(self, meth, *args): conn = self.getConnection() try: > val = meth(conn, *args) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:228] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _queryAll(self, conn, s): if self.debug: self.printDebug(conn, s, 'QueryAll') c = conn.cursor() > self._executeRetry(conn, c, s) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:320] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _executeRetry(self, conn, cursor, query): if self.debug: self.printDebug(conn, query, 'QueryR') E return cursor.execute(query) > OperationalError: no such column: person_id [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:306] - - - - - - - - - - - test_dynamicJoin: recorded stdout - - - - - - - - - - - 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/Query : DELETE FROM person 1/QueryR : DELETE FROM person 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/Query : DELETE FROM phone 1/QueryR : DELETE FROM phone 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('jane') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 1 1/QueryR : SELECT name_col FROM person WHERE id = 1 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('tim') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 2 1/QueryR : SELECT name_col FROM person WHERE id = 2 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('bob') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 3 1/QueryR : SELECT name_col FROM person WHERE id = 3 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('jake') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 4 1/QueryR : SELECT name_col FROM person WHERE id = 4 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('555-555-5555') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 1 1/QueryR : SELECT phone FROM phone WHERE id = 1 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('555-394-2930') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 2 1/QueryR : SELECT phone FROM phone WHERE id = 2 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('444-382-4854') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 3 1/QueryR : SELECT phone FROM phone WHERE id = 3 1/COMMIT : auto 1/Query : ALTER TABLE phone ADD COLUMN person_i_d_id INT 1/QueryR : ALTER TABLE phone ADD COLUMN person_i_d_id INT 1/COMMIT : auto 1/Select : SELECT phone.id, phone.phone, phone.person_i_d_id FROM phone WHERE 1 = 1 ORDER BY phone 1/QueryR : SELECT phone.id, phone.phone, phone.person_i_d_id FROM phone WHERE 1 = 1 ORDER BY phone 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'bob' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'bob' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/QueryAll: SELECT id FROM phone WHERE person_id = 2 1/QueryR : SELECT id FROM phone WHERE person_id = 2 1/COMMIT : auto ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-15 16:54 Message: Logged In: YES user_id=140558 Ok, here I go again. I've fixed a small bug: the name of the field was not porperly set when using Key(foreignKey... instead of ForeignKey. This fixes test_basic. And I think that there is nothing else to fix, I'm probably wrong, but I'll explain it hera. test_auto_old.py... FAIL test_auto.py... FAIL test_foreignKey.py... FAIL These tests fail because sqlite is failing when adding columns. In mysql it does not fail. I do not think it's this patch fault. And finally: test_SQLMultipleJoin.py... FAIL E assert str(hibrid.fightersAsSResult.sum('power')) == '23' > assert '23.0' == '23' + where '23.0' = str(23.0) + where 23.0 = <Race 3 name="'hibrid (human wi...'">.fightersAsSResult.sum('power') Again this is an error in the test. Please let me know if it can go in now :) If you can have a quick look at it better, it takes time to restart ths tests, I'd rather do it before I move on to another thing. Thanks Pau ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-14 10:05 Message: Logged In: YES user_id=140558 Oleg, I've posted to the list because I run the tests and pass. I'm sure I'm doing something wrong but I don't see what. I lost more than 3 hours yesterday just trying to run te tests :( I printed things in dbtest.py and say that TESTDB did not change anything. I chenged manually conftest.py because I ahd a message that yoiu need sqlite2 for memory databases, but still I'm not sure everything works becasue I pass al the tests. Can you help me, I want to close this patch soon and move to other improvements but this is being much more difficult than it should. Thanks a lot Pau ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-09 17:42 Message: Logged In: YES user_id=140558 I'm very busy but again will try to find some time to fix it. I'm using it every day without a glitch, even using the clause attributes like in the Complex example (new type of joins *toMany). I'll update it to latest SVN just in case this is the problem, I did it with that day's current. Please do not close it, I really intend to pass the tests, I'm already using it. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-09 17:11 Message: Logged In: YES user_id=4799 test_auto.py, for example fails: def test_dynamicJoin(self): col = KeyCol('personID', foreignKey='Person') Phone.sqlmeta.addColumn(col, changeSchema=True) join = MultipleJoin('Phone') Person.sqlmeta.addJoin(join) for phone in Phone.select('all'): if phone.phone.startswith('555'): phone.person = Person.selectBy(name='tim')[0] else: phone.person = Person.selectBy(name='bob')[0] l = [p.phone for p in Person.selectBy(name='tim')[0].phones] l.sort() E assert l == ['555-394-2930', '555-555-5555'] > assert [] == ['555-394-2930', '555-555-5555'] [sqlobject/tests/test_auto.py:61] ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-30 19:10 Message: Logged In: YES user_id=140558 I'll recheck it, it really passed all the tests applied to the latest svn. I tell you something tomorrow. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-30 19:07 Message: Logged In: YES user_id=140558 I'll recheck it, it really passed all the tests applied to the latest svn. I tell you something tomorrow. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-30 18:57 Message: Logged In: YES user_id=4799 test_auto.py, test_auto_old.py and test_basic.py failed. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-18 17:04 Message: Logged In: YES user_id=140558 This is the final patch against latest svn, it includes everything in one single patch. It passes the tests. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-18 14:17 Message: Logged In: YES user_id=140558 Ok, I have taken my time to understand pydist, test, etc, and here I am back with the working solution :) Now the resulting SQLobject passes all the tests. I attach an incremental patch so that you can see more clearly the changes done to fix the previous one. I've needed a new method in the Style class, instanceIDAttrToAttr, that is the complementary to the already known instanceAttrToIDAttr. If you need to transform back and forth field names, you need them both. I haven't tried to port it to the latest svn yet, this is against the same release than the first patch, but it should apply more or less clearly as this are very isolated areas in the code. When I do it I'll post it here. Sorry for the delay, it has not been easy for me to understand more deeply the code and, even less, to know how the tests work :) ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-03 13:18 Message: Logged In: YES user_id=140558 It fails because the test is not right, it still has the ID postfix hardcoded. My fault, I did no send a patch for tests. This is the piece that fails: # Select by usual way s = TestWorkKey.selectBy(composerID=c.id, title='Symphony No. 9') I have not looked at tests until now, but it looks like there should be tests for the different provides styles, in this case, if you accept the patch, at least a test for the LongStyle provided and for the current naming styles. I'll try to cook up something, but it can take a little time. Any guidelines will be appreciated (I've just read the docs ;) ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-03 12:23 Message: Logged In: YES user_id=4799 test_selectBy_foreignKey.py fails: def test1(): setupClass([TestComposerKey, TestWorkKey]) c = TestComposerKey(name='Mahler, Gustav') > w1 = TestWorkKey(composer=c, title='Symphony No. 9') [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/tests/test_selectBy_foreignKey.py:19] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def __init__(self, **kw): # The get() classmethod/constructor uses a magic keyword # argument when it wants an empty object, fetched from the # database. So we have nothing more to do in that case: if kw.has_key('_SO_fetch_no_create'): return post_funcs = [] self.sqlmeta.send(events.RowCreateSignal, kw, post_funcs) # Pass the connection object along if we were given one. if kw.has_key('connection'): self._connection = kw['connection'] self.sqlmeta._perConnection = True del kw['connection'] self._SO_writeLock = threading.Lock() if kw.has_key('id'): id = self.sqlmeta.idType(kw['id']) del kw['id'] else: id = None > self._create(id, **kw) [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/main.py:1210] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _create(self, id, **kw): self.sqlmeta._creating = True self._SO_createValues = {} self._SO_validatorState = SQLObjectState(self) # First we do a little fix-up on the keywords we were # passed: for column in self.sqlmeta.columnList: # Then we check if the column wasn't passed in, and # if not we try to get the default. if not kw.has_key(column.name) and not kw.has_key(column.foreignName): default = column.default # If we don't get it, it's an error: if default is NoDefault: E raise TypeError, "%s() did not get expected keyword argument %s" % (self.__class__.__name__, column.name) > TypeError: TestWorkKey() did not get expected keyword argument composerID [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/main.py:1231] - - - - - - - - - - - - - test1: recorded stdout - - - - - - - - - - - - - - 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/Query : CREATE TABLE test_composer_key ( id SERIAL PRIMARY KEY, name TEXT ) 1/QueryR : CREATE TABLE test_composer_key ( id SERIAL PRIMARY KEY, name TEXT ) 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/Query : CREATE TABLE test_work_key ( work_id SERIAL PRIMARY KEY, composer_id INT, title TEXT ) 1/QueryR : CREATE TABLE test_work_key ( work_id SERIAL PRIMARY KEY, composer_id INT, title TEXT ) 1/COMMIT : auto 1/Query : ALTER TABLE test_work_key ADD CONSTRAINT composer_id_exists FOREIGN KEY (composer_id) REFERENCES test_composer_key (id) 1/QueryR : ALTER TABLE test_work_key ADD CONSTRAINT composer_id_exists FOREIGN KEY (composer_id) REFERENCES test_composer_key (id) 1/COMMIT : auto 1/QueryIns: INSERT INTO test_composer_key (id, name) VALUES (1, 'Mahler, Gustav') 1/COMMIT : auto 1/QueryOne: SELECT name FROM test_composer_key WHERE id = 1 1/QueryR : SELECT name FROM test_composer_key WHERE id = 1 1/COMMIT : auto ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1353728&group_id=74338 |
|
From: SourceForge.net <no...@so...> - 2006-02-17 16:58:45
|
Patches item #1353728, was opened at 2005-11-11 10:20 Message generated for change (Comment added) made by phd You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1353728&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Submitted By: Pau Aliagas (linux4u) Assigned to: Oleg Broytmann (phd) Summary: define foreign keys in Style Initial Comment: I don't like to use attrID all along the code to access related tables, I want to be able use the nomeclature I like taking advantage of the nice Style idea. This is especially true when you create RelatedJoins when you use a nomeclature like I do (table.id_table), but it's the same for all the nomeclatures you can imagine. In styles.py it warns: def instanceAttrToIDAttr(self, attr): # @@: Right now, because of how names are created for foreign # keys, you can't really change this style. return attr + "ID" With this patch you can define how you want the foreign keys generated, they won't be mandatorily generated as attrID. Example: class LongStyle(Style): """ This style is derived from Style, that does not do any translation, but constructs the table ids like id_table. """ def instanceAttrToIDAttr(self, attr): return "id_" + attr def tableReference(self, table): # str.rsplit is python 2.4+ only if version_info >= (2, 4): return "id_" + table.rsplit(".", 1)[-1] else: return "id_" + rsplit(table, ".", 1)[-1] class mm_server(SQLObject): class sqlmeta: table = "smsarena.mm_server" style = LongStyle(longID = True) _connection = conn_smsarena server = StringCol(alternateID = True, varchar = True, length = 255, alternateMethodName = "by_server") tz = StringCol(length = 20, default = 'CET', notNone = True) conutry_code = StringCol(length = 2, varchar = False, default = '', notNone = True) # until now I had to do this # mm_server_aliases = SQLMultipleJoin("mm_server_alias", joinColumn = "mm_serverID", orderBy = "server") # now it's perfect! mm_server_aliases = SQLMultipleJoin("mm_server_alias", orderBy = "server") class mm_server_alias(SQLObject): class sqlmeta: table = "smsarena.mm_server_alias" style = LongStyle(longID = True) _connection = conn_smsarena # until now I had to do this # mm_server = ForeignKey("mm_server", dbName = "id_mm_server") mm_server = ForeignKey("mm_server") server = StringCol(alternateID = True, varchar = True, length = 255, alternateMethodName = "by_server") I hope it's clear :) Pau ---------------------------------------------------------------------- >Comment By: Oleg Broytmann (phd) Date: 2006-02-17 19:58 Message: Logged In: YES user_id=4799 Please do. I reopened the patch. Instead of one-line patch for Style IWBN to make a smaller (than the original) patch that avoids patching .addColumn() in tests, isn't it? ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 19:39 Message: Logged In: YES user_id=140558 This can be solve with a onliner in default style: if not name.endswith("ID")... IMHO doing addColumn(fieldID, ForeignKey..) is a mistake You should do addColumn(field, ForeignKey..) and style takes care of it. If you want I can submit this oneliner for 0.7 only and you reconsider ading it to 0.7. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 19:29 Message: Logged In: YES user_id=4799 Even that's a big change, too big for 0.7 bugfix. Don't hesitate to post patches or at least bug reports for other issues. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 19:12 Message: Logged In: YES user_id=140558 Answering your concerns about the API... The only change is the one I have explained when using addColumn(fieldID, ForeignKey..). If you put ID, the current default style rules would add it too, so you'd get fieldIDID. We could change the style rules and look at this case, but I think that the current behaviour (as it is now with the patch) is completly orthogonal and always acts the same way, no black magic required. For the rest this is a HUGE addition!! You don't need to worry anymore about namning styles, nothing is written in stone. the ID thing was everywhere in the code Combined with the other patch (select using the object, not the id), you can almost always avoid referring directly to foreign field names. I really feel much more comfortable with these changes applied, seeign fieldID in the code maed me feel that something was not competely right. Avoiding it makes the code look beautiful. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 19:06 Message: Logged In: YES user_id=4799 SUM() should return whtaver the DB returns. I think summing an INT column returns an int, summing a FLOAT column returns a float. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 18:59 Message: Logged In: YES user_id=140558 Ok, another test mistery solved: This is the culprit that test_SQLMultipleJoin.py fails: assert str(hibrid.fightersAsSResult.sum('power')) == '23' In pgsql hibrid.fightersAsSResult.sum('power') returns 23. In sqlite-3.1.2 and mysql-4.1 it returns 23.0. So we should either fix the test or the sum function. Fixing the test could be as easy as casting the float to int: assert str(int(hibrid.fightersAsSResult.sum('power'))) == '23' but I'mn not sure if this would hide a bug. Should sum return float or int? ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 18:55 Message: Logged In: YES user_id=4799 Yes, it works finally! Applied in the revision 1607. Thank you for the job! How much does it change the API? Does it have meaning to be applied to 0.7 branch? I actually applied it and it passed all tests, but I don't want to break API for 0.7.1. Will all old programs work? ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 18:49 Message: Logged In: YES user_id=140558 After fixing my patch (I'm sure it works now!!) I'm reviewing the tests that fail. See the attached file "failed tests 2006-01-17 version 1" for the tests an the detailed explanations. In summary: test_ForeignKey.py: you know about it, it fails in all the databases test_SQLMultipleJoin.py: I don't see why it fails, it fails in sqlite and mysql, not in pgsql * sqlite * my problem is that sqlite-3.1.2 does not support alter tabble ad column, so no problem. * mysql * test_datetime.py ---------------- to_python does not seem to work as expected. test_enum.py ------------ BLOB/TEXT column indexes require length in mysql I hope that this makes clear the current status. If you accept the current patch, maybe we could open another ticket with the current bugs in mysql and sqlite, as these are clearly separate issues. Thanks ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 16:26 Message: Logged In: YES user_id=140558 I've fixed the problems with addColumns and delColum, now it passes the tests (not the ones that fail I do not why). I've fixed the tests too: I think we should NOT add the columns with ID at the end as the style add it for you. Otherwise I should modify the sytle functions to conditionally check if they end in ID.... I don't think that it is ok, if we want that, we define anthjer style that removes double ID at the end. This is internal to the style and so should be kept. Hope it's ok now :) ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 16:01 Message: Logged In: YES user_id=140558 These are my versions (ignore my comment in the other patch ticket, my misake): mysql-4.1.16-1.FC4.1 postgresql-8.0.7-1.FC4.1 python-psycopg-1.1.21-1.fc4 python-sqlite-1.1.6-1 sqlite-3.1.2-3 ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 15:38 Message: Logged In: YES user_id=4799 Except for the problem i test_ForeignKey.py that I know about... others look pretty strange. Let look at the environment. What DB versions? MySQL, PgSQL, SQLite? Drivers versions? MySQLdb, psycopg, PySQLite? MyPostgres is 7.4, psycopg 1.1.21 and 2.0b5. PySQLite 1.1.7 and 2.1.3. A week ago I upgarded to SQLite 3.3.3 and PySQLite 2.1.3; that eliminated some minor problems with patches I have had with SQLIte 2.8.0 and PySQLite 2.1.0. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 15:11 Message: Logged In: YES user_id=140558 Ok, plain SQLObject from SVN now, no patch. There are tests that fail for me in current SQLObject in mysql, postgres and sqlite. I attach them all. This is a fully updated Fedora 4. I've made the tests in mysql and there are some thet do not pass. I enclose the results and a file where I comment why the fail and a possible solution. The tests that fail in postgres and sqlite are the ones I've already reported (mnore or less). Any help? ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 12:22 Message: Logged In: YES user_id=4799 No, the latest SQLObject passes all tests (how would I commit your other patch if a test fail?) except for minor glitch in test_ForeignKey.py which I'm going to resolve RSN. test_auto.py certainly pass. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 12:13 Message: Logged In: YES user_id=140558 I've run the test with the latest SQLObject (no extra patches) and the tests fail too, at least they fail when I run them. As I explained before, there's something wrong when adding columns to sqlite, it fails and all the tests that depend on the added columns fail too. Does it happen to you too? ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-16 18:16 Message: Logged In: YES user_id=4799 These tests fail in both Postgres and SQLite. Two major backends (of 3) for SQLObject. If the problem is in tests you can patch tests, too... test_auto.py: def test_dynamicJoin(self): col = KeyCol('personID', foreignKey='Person') Phone.sqlmeta.addColumn(col, changeSchema=True) join = MultipleJoin('Phone') Person.sqlmeta.addJoin(join) for phone in Phone.select('all'): if phone.phone.startswith('555'): phone.person = Person.selectBy(name='tim')[0] else: phone.person = Person.selectBy(name='bob')[0] > l = [p.phone for p in Person.selectBy(name='tim')[0].phones] [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/test_auto.py:59] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > [failure to get at sourcelines from <TracebackEntry /home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/<string>:1>] [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/<string>:1] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def performJoin(self, inst): ids = inst._connection._SO_selectJoin( self.otherClass, self.joinColumn, > inst.id) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/joins.py:144] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _SO_selectJoin(self, soClass, column, value): return self.queryAll("SELECT %s FROM %s WHERE %s = %s" % (soClass.sqlmeta.idName, soClass.sqlmeta.table, column, > self.sqlrepr(value))) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:652] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def queryAll(self, s): > return self._runWithConnection(self._queryAll, s) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:327] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _runWithConnection(self, meth, *args): conn = self.getConnection() try: > val = meth(conn, *args) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:228] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _queryAll(self, conn, s): if self.debug: self.printDebug(conn, s, 'QueryAll') c = conn.cursor() > self._executeRetry(conn, c, s) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:320] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _executeRetry(self, conn, cursor, query): if self.debug: self.printDebug(conn, query, 'QueryR') E return cursor.execute(query) > OperationalError: no such column: person_id [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:306] - - - - - - - - - - - test_dynamicJoin: recorded stdout - - - - - - - - - - - 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/Query : DELETE FROM person 1/QueryR : DELETE FROM person 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/Query : DELETE FROM phone 1/QueryR : DELETE FROM phone 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('jane') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 1 1/QueryR : SELECT name_col FROM person WHERE id = 1 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('tim') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 2 1/QueryR : SELECT name_col FROM person WHERE id = 2 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('bob') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 3 1/QueryR : SELECT name_col FROM person WHERE id = 3 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('jake') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 4 1/QueryR : SELECT name_col FROM person WHERE id = 4 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('555-555-5555') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 1 1/QueryR : SELECT phone FROM phone WHERE id = 1 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('555-394-2930') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 2 1/QueryR : SELECT phone FROM phone WHERE id = 2 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('444-382-4854') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 3 1/QueryR : SELECT phone FROM phone WHERE id = 3 1/COMMIT : auto 1/Query : ALTER TABLE phone ADD COLUMN person_i_d_id INT 1/QueryR : ALTER TABLE phone ADD COLUMN person_i_d_id INT 1/COMMIT : auto 1/Select : SELECT phone.id, phone.phone, phone.person_i_d_id FROM phone WHERE 1 = 1 ORDER BY phone 1/QueryR : SELECT phone.id, phone.phone, phone.person_i_d_id FROM phone WHERE 1 = 1 ORDER BY phone 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'bob' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'bob' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/QueryAll: SELECT id FROM phone WHERE person_id = 2 1/QueryR : SELECT id FROM phone WHERE person_id = 2 1/COMMIT : auto ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-15 18:54 Message: Logged In: YES user_id=140558 Ok, here I go again. I've fixed a small bug: the name of the field was not porperly set when using Key(foreignKey... instead of ForeignKey. This fixes test_basic. And I think that there is nothing else to fix, I'm probably wrong, but I'll explain it hera. test_auto_old.py... FAIL test_auto.py... FAIL test_foreignKey.py... FAIL These tests fail because sqlite is failing when adding columns. In mysql it does not fail. I do not think it's this patch fault. And finally: test_SQLMultipleJoin.py... FAIL E assert str(hibrid.fightersAsSResult.sum('power')) == '23' > assert '23.0' == '23' + where '23.0' = str(23.0) + where 23.0 = <Race 3 name="'hibrid (human wi...'">.fightersAsSResult.sum('power') Again this is an error in the test. Please let me know if it can go in now :) If you can have a quick look at it better, it takes time to restart ths tests, I'd rather do it before I move on to another thing. Thanks Pau ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-14 12:05 Message: Logged In: YES user_id=140558 Oleg, I've posted to the list because I run the tests and pass. I'm sure I'm doing something wrong but I don't see what. I lost more than 3 hours yesterday just trying to run te tests :( I printed things in dbtest.py and say that TESTDB did not change anything. I chenged manually conftest.py because I ahd a message that yoiu need sqlite2 for memory databases, but still I'm not sure everything works becasue I pass al the tests. Can you help me, I want to close this patch soon and move to other improvements but this is being much more difficult than it should. Thanks a lot Pau ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-09 19:42 Message: Logged In: YES user_id=140558 I'm very busy but again will try to find some time to fix it. I'm using it every day without a glitch, even using the clause attributes like in the Complex example (new type of joins *toMany). I'll update it to latest SVN just in case this is the problem, I did it with that day's current. Please do not close it, I really intend to pass the tests, I'm already using it. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-09 19:11 Message: Logged In: YES user_id=4799 test_auto.py, for example fails: def test_dynamicJoin(self): col = KeyCol('personID', foreignKey='Person') Phone.sqlmeta.addColumn(col, changeSchema=True) join = MultipleJoin('Phone') Person.sqlmeta.addJoin(join) for phone in Phone.select('all'): if phone.phone.startswith('555'): phone.person = Person.selectBy(name='tim')[0] else: phone.person = Person.selectBy(name='bob')[0] l = [p.phone for p in Person.selectBy(name='tim')[0].phones] l.sort() E assert l == ['555-394-2930', '555-555-5555'] > assert [] == ['555-394-2930', '555-555-5555'] [sqlobject/tests/test_auto.py:61] ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-30 21:10 Message: Logged In: YES user_id=140558 I'll recheck it, it really passed all the tests applied to the latest svn. I tell you something tomorrow. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-30 21:07 Message: Logged In: YES user_id=140558 I'll recheck it, it really passed all the tests applied to the latest svn. I tell you something tomorrow. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-30 20:57 Message: Logged In: YES user_id=4799 test_auto.py, test_auto_old.py and test_basic.py failed. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-18 19:04 Message: Logged In: YES user_id=140558 This is the final patch against latest svn, it includes everything in one single patch. It passes the tests. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-18 16:17 Message: Logged In: YES user_id=140558 Ok, I have taken my time to understand pydist, test, etc, and here I am back with the working solution :) Now the resulting SQLobject passes all the tests. I attach an incremental patch so that you can see more clearly the changes done to fix the previous one. I've needed a new method in the Style class, instanceIDAttrToAttr, that is the complementary to the already known instanceAttrToIDAttr. If you need to transform back and forth field names, you need them both. I haven't tried to port it to the latest svn yet, this is against the same release than the first patch, but it should apply more or less clearly as this are very isolated areas in the code. When I do it I'll post it here. Sorry for the delay, it has not been easy for me to understand more deeply the code and, even less, to know how the tests work :) ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-03 15:18 Message: Logged In: YES user_id=140558 It fails because the test is not right, it still has the ID postfix hardcoded. My fault, I did no send a patch for tests. This is the piece that fails: # Select by usual way s = TestWorkKey.selectBy(composerID=c.id, title='Symphony No. 9') I have not looked at tests until now, but it looks like there should be tests for the different provides styles, in this case, if you accept the patch, at least a test for the LongStyle provided and for the current naming styles. I'll try to cook up something, but it can take a little time. Any guidelines will be appreciated (I've just read the docs ;) ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-03 14:23 Message: Logged In: YES user_id=4799 test_selectBy_foreignKey.py fails: def test1(): setupClass([TestComposerKey, TestWorkKey]) c = TestComposerKey(name='Mahler, Gustav') > w1 = TestWorkKey(composer=c, title='Symphony No. 9') [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/tests/test_selectBy_foreignKey.py:19] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def __init__(self, **kw): # The get() classmethod/constructor uses a magic keyword # argument when it wants an empty object, fetched from the # database. So we have nothing more to do in that case: if kw.has_key('_SO_fetch_no_create'): return post_funcs = [] self.sqlmeta.send(events.RowCreateSignal, kw, post_funcs) # Pass the connection object along if we were given one. if kw.has_key('connection'): self._connection = kw['connection'] self.sqlmeta._perConnection = True del kw['connection'] self._SO_writeLock = threading.Lock() if kw.has_key('id'): id = self.sqlmeta.idType(kw['id']) del kw['id'] else: id = None > self._create(id, **kw) [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/main.py:1210] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _create(self, id, **kw): self.sqlmeta._creating = True self._SO_createValues = {} self._SO_validatorState = SQLObjectState(self) # First we do a little fix-up on the keywords we were # passed: for column in self.sqlmeta.columnList: # Then we check if the column wasn't passed in, and # if not we try to get the default. if not kw.has_key(column.name) and not kw.has_key(column.foreignName): default = column.default # If we don't get it, it's an error: if default is NoDefault: E raise TypeError, "%s() did not get expected keyword argument %s" % (self.__class__.__name__, column.name) > TypeError: TestWorkKey() did not get expected keyword argument composerID [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/main.py:1231] - - - - - - - - - - - - - test1: recorded stdout - - - - - - - - - - - - - - 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/Query : CREATE TABLE test_composer_key ( id SERIAL PRIMARY KEY, name TEXT ) 1/QueryR : CREATE TABLE test_composer_key ( id SERIAL PRIMARY KEY, name TEXT ) 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/Query : CREATE TABLE test_work_key ( work_id SERIAL PRIMARY KEY, composer_id INT, title TEXT ) 1/QueryR : CREATE TABLE test_work_key ( work_id SERIAL PRIMARY KEY, composer_id INT, title TEXT ) 1/COMMIT : auto 1/Query : ALTER TABLE test_work_key ADD CONSTRAINT composer_id_exists FOREIGN KEY (composer_id) REFERENCES test_composer_key (id) 1/QueryR : ALTER TABLE test_work_key ADD CONSTRAINT composer_id_exists FOREIGN KEY (composer_id) REFERENCES test_composer_key (id) 1/COMMIT : auto 1/QueryIns: INSERT INTO test_composer_key (id, name) VALUES (1, 'Mahler, Gustav') 1/COMMIT : auto 1/QueryOne: SELECT name FROM test_composer_key WHERE id = 1 1/QueryR : SELECT name FROM test_composer_key WHERE id = 1 1/COMMIT : auto ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1353728&group_id=74338 |
|
From: SourceForge.net <no...@so...> - 2006-02-17 16:53:40
|
Patches item #1353728, was opened at 2005-11-11 10:20 Message generated for change (Settings changed) made by phd You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1353728&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None >Status: Open >Resolution: None Priority: 5 Submitted By: Pau Aliagas (linux4u) Assigned to: Oleg Broytmann (phd) Summary: define foreign keys in Style Initial Comment: I don't like to use attrID all along the code to access related tables, I want to be able use the nomeclature I like taking advantage of the nice Style idea. This is especially true when you create RelatedJoins when you use a nomeclature like I do (table.id_table), but it's the same for all the nomeclatures you can imagine. In styles.py it warns: def instanceAttrToIDAttr(self, attr): # @@: Right now, because of how names are created for foreign # keys, you can't really change this style. return attr + "ID" With this patch you can define how you want the foreign keys generated, they won't be mandatorily generated as attrID. Example: class LongStyle(Style): """ This style is derived from Style, that does not do any translation, but constructs the table ids like id_table. """ def instanceAttrToIDAttr(self, attr): return "id_" + attr def tableReference(self, table): # str.rsplit is python 2.4+ only if version_info >= (2, 4): return "id_" + table.rsplit(".", 1)[-1] else: return "id_" + rsplit(table, ".", 1)[-1] class mm_server(SQLObject): class sqlmeta: table = "smsarena.mm_server" style = LongStyle(longID = True) _connection = conn_smsarena server = StringCol(alternateID = True, varchar = True, length = 255, alternateMethodName = "by_server") tz = StringCol(length = 20, default = 'CET', notNone = True) conutry_code = StringCol(length = 2, varchar = False, default = '', notNone = True) # until now I had to do this # mm_server_aliases = SQLMultipleJoin("mm_server_alias", joinColumn = "mm_serverID", orderBy = "server") # now it's perfect! mm_server_aliases = SQLMultipleJoin("mm_server_alias", orderBy = "server") class mm_server_alias(SQLObject): class sqlmeta: table = "smsarena.mm_server_alias" style = LongStyle(longID = True) _connection = conn_smsarena # until now I had to do this # mm_server = ForeignKey("mm_server", dbName = "id_mm_server") mm_server = ForeignKey("mm_server") server = StringCol(alternateID = True, varchar = True, length = 255, alternateMethodName = "by_server") I hope it's clear :) Pau ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 19:39 Message: Logged In: YES user_id=140558 This can be solve with a onliner in default style: if not name.endswith("ID")... IMHO doing addColumn(fieldID, ForeignKey..) is a mistake You should do addColumn(field, ForeignKey..) and style takes care of it. If you want I can submit this oneliner for 0.7 only and you reconsider ading it to 0.7. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 19:29 Message: Logged In: YES user_id=4799 Even that's a big change, too big for 0.7 bugfix. Don't hesitate to post patches or at least bug reports for other issues. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 19:12 Message: Logged In: YES user_id=140558 Answering your concerns about the API... The only change is the one I have explained when using addColumn(fieldID, ForeignKey..). If you put ID, the current default style rules would add it too, so you'd get fieldIDID. We could change the style rules and look at this case, but I think that the current behaviour (as it is now with the patch) is completly orthogonal and always acts the same way, no black magic required. For the rest this is a HUGE addition!! You don't need to worry anymore about namning styles, nothing is written in stone. the ID thing was everywhere in the code Combined with the other patch (select using the object, not the id), you can almost always avoid referring directly to foreign field names. I really feel much more comfortable with these changes applied, seeign fieldID in the code maed me feel that something was not competely right. Avoiding it makes the code look beautiful. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 19:06 Message: Logged In: YES user_id=4799 SUM() should return whtaver the DB returns. I think summing an INT column returns an int, summing a FLOAT column returns a float. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 18:59 Message: Logged In: YES user_id=140558 Ok, another test mistery solved: This is the culprit that test_SQLMultipleJoin.py fails: assert str(hibrid.fightersAsSResult.sum('power')) == '23' In pgsql hibrid.fightersAsSResult.sum('power') returns 23. In sqlite-3.1.2 and mysql-4.1 it returns 23.0. So we should either fix the test or the sum function. Fixing the test could be as easy as casting the float to int: assert str(int(hibrid.fightersAsSResult.sum('power'))) == '23' but I'mn not sure if this would hide a bug. Should sum return float or int? ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 18:55 Message: Logged In: YES user_id=4799 Yes, it works finally! Applied in the revision 1607. Thank you for the job! How much does it change the API? Does it have meaning to be applied to 0.7 branch? I actually applied it and it passed all tests, but I don't want to break API for 0.7.1. Will all old programs work? ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 18:49 Message: Logged In: YES user_id=140558 After fixing my patch (I'm sure it works now!!) I'm reviewing the tests that fail. See the attached file "failed tests 2006-01-17 version 1" for the tests an the detailed explanations. In summary: test_ForeignKey.py: you know about it, it fails in all the databases test_SQLMultipleJoin.py: I don't see why it fails, it fails in sqlite and mysql, not in pgsql * sqlite * my problem is that sqlite-3.1.2 does not support alter tabble ad column, so no problem. * mysql * test_datetime.py ---------------- to_python does not seem to work as expected. test_enum.py ------------ BLOB/TEXT column indexes require length in mysql I hope that this makes clear the current status. If you accept the current patch, maybe we could open another ticket with the current bugs in mysql and sqlite, as these are clearly separate issues. Thanks ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 16:26 Message: Logged In: YES user_id=140558 I've fixed the problems with addColumns and delColum, now it passes the tests (not the ones that fail I do not why). I've fixed the tests too: I think we should NOT add the columns with ID at the end as the style add it for you. Otherwise I should modify the sytle functions to conditionally check if they end in ID.... I don't think that it is ok, if we want that, we define anthjer style that removes double ID at the end. This is internal to the style and so should be kept. Hope it's ok now :) ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 16:01 Message: Logged In: YES user_id=140558 These are my versions (ignore my comment in the other patch ticket, my misake): mysql-4.1.16-1.FC4.1 postgresql-8.0.7-1.FC4.1 python-psycopg-1.1.21-1.fc4 python-sqlite-1.1.6-1 sqlite-3.1.2-3 ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 15:38 Message: Logged In: YES user_id=4799 Except for the problem i test_ForeignKey.py that I know about... others look pretty strange. Let look at the environment. What DB versions? MySQL, PgSQL, SQLite? Drivers versions? MySQLdb, psycopg, PySQLite? MyPostgres is 7.4, psycopg 1.1.21 and 2.0b5. PySQLite 1.1.7 and 2.1.3. A week ago I upgarded to SQLite 3.3.3 and PySQLite 2.1.3; that eliminated some minor problems with patches I have had with SQLIte 2.8.0 and PySQLite 2.1.0. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 15:11 Message: Logged In: YES user_id=140558 Ok, plain SQLObject from SVN now, no patch. There are tests that fail for me in current SQLObject in mysql, postgres and sqlite. I attach them all. This is a fully updated Fedora 4. I've made the tests in mysql and there are some thet do not pass. I enclose the results and a file where I comment why the fail and a possible solution. The tests that fail in postgres and sqlite are the ones I've already reported (mnore or less). Any help? ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 12:22 Message: Logged In: YES user_id=4799 No, the latest SQLObject passes all tests (how would I commit your other patch if a test fail?) except for minor glitch in test_ForeignKey.py which I'm going to resolve RSN. test_auto.py certainly pass. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 12:13 Message: Logged In: YES user_id=140558 I've run the test with the latest SQLObject (no extra patches) and the tests fail too, at least they fail when I run them. As I explained before, there's something wrong when adding columns to sqlite, it fails and all the tests that depend on the added columns fail too. Does it happen to you too? ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-16 18:16 Message: Logged In: YES user_id=4799 These tests fail in both Postgres and SQLite. Two major backends (of 3) for SQLObject. If the problem is in tests you can patch tests, too... test_auto.py: def test_dynamicJoin(self): col = KeyCol('personID', foreignKey='Person') Phone.sqlmeta.addColumn(col, changeSchema=True) join = MultipleJoin('Phone') Person.sqlmeta.addJoin(join) for phone in Phone.select('all'): if phone.phone.startswith('555'): phone.person = Person.selectBy(name='tim')[0] else: phone.person = Person.selectBy(name='bob')[0] > l = [p.phone for p in Person.selectBy(name='tim')[0].phones] [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/test_auto.py:59] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > [failure to get at sourcelines from <TracebackEntry /home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/<string>:1>] [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/<string>:1] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def performJoin(self, inst): ids = inst._connection._SO_selectJoin( self.otherClass, self.joinColumn, > inst.id) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/joins.py:144] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _SO_selectJoin(self, soClass, column, value): return self.queryAll("SELECT %s FROM %s WHERE %s = %s" % (soClass.sqlmeta.idName, soClass.sqlmeta.table, column, > self.sqlrepr(value))) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:652] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def queryAll(self, s): > return self._runWithConnection(self._queryAll, s) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:327] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _runWithConnection(self, meth, *args): conn = self.getConnection() try: > val = meth(conn, *args) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:228] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _queryAll(self, conn, s): if self.debug: self.printDebug(conn, s, 'QueryAll') c = conn.cursor() > self._executeRetry(conn, c, s) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:320] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _executeRetry(self, conn, cursor, query): if self.debug: self.printDebug(conn, query, 'QueryR') E return cursor.execute(query) > OperationalError: no such column: person_id [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:306] - - - - - - - - - - - test_dynamicJoin: recorded stdout - - - - - - - - - - - 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/Query : DELETE FROM person 1/QueryR : DELETE FROM person 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/Query : DELETE FROM phone 1/QueryR : DELETE FROM phone 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('jane') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 1 1/QueryR : SELECT name_col FROM person WHERE id = 1 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('tim') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 2 1/QueryR : SELECT name_col FROM person WHERE id = 2 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('bob') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 3 1/QueryR : SELECT name_col FROM person WHERE id = 3 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('jake') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 4 1/QueryR : SELECT name_col FROM person WHERE id = 4 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('555-555-5555') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 1 1/QueryR : SELECT phone FROM phone WHERE id = 1 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('555-394-2930') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 2 1/QueryR : SELECT phone FROM phone WHERE id = 2 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('444-382-4854') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 3 1/QueryR : SELECT phone FROM phone WHERE id = 3 1/COMMIT : auto 1/Query : ALTER TABLE phone ADD COLUMN person_i_d_id INT 1/QueryR : ALTER TABLE phone ADD COLUMN person_i_d_id INT 1/COMMIT : auto 1/Select : SELECT phone.id, phone.phone, phone.person_i_d_id FROM phone WHERE 1 = 1 ORDER BY phone 1/QueryR : SELECT phone.id, phone.phone, phone.person_i_d_id FROM phone WHERE 1 = 1 ORDER BY phone 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'bob' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'bob' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/QueryAll: SELECT id FROM phone WHERE person_id = 2 1/QueryR : SELECT id FROM phone WHERE person_id = 2 1/COMMIT : auto ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-15 18:54 Message: Logged In: YES user_id=140558 Ok, here I go again. I've fixed a small bug: the name of the field was not porperly set when using Key(foreignKey... instead of ForeignKey. This fixes test_basic. And I think that there is nothing else to fix, I'm probably wrong, but I'll explain it hera. test_auto_old.py... FAIL test_auto.py... FAIL test_foreignKey.py... FAIL These tests fail because sqlite is failing when adding columns. In mysql it does not fail. I do not think it's this patch fault. And finally: test_SQLMultipleJoin.py... FAIL E assert str(hibrid.fightersAsSResult.sum('power')) == '23' > assert '23.0' == '23' + where '23.0' = str(23.0) + where 23.0 = <Race 3 name="'hibrid (human wi...'">.fightersAsSResult.sum('power') Again this is an error in the test. Please let me know if it can go in now :) If you can have a quick look at it better, it takes time to restart ths tests, I'd rather do it before I move on to another thing. Thanks Pau ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-14 12:05 Message: Logged In: YES user_id=140558 Oleg, I've posted to the list because I run the tests and pass. I'm sure I'm doing something wrong but I don't see what. I lost more than 3 hours yesterday just trying to run te tests :( I printed things in dbtest.py and say that TESTDB did not change anything. I chenged manually conftest.py because I ahd a message that yoiu need sqlite2 for memory databases, but still I'm not sure everything works becasue I pass al the tests. Can you help me, I want to close this patch soon and move to other improvements but this is being much more difficult than it should. Thanks a lot Pau ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-09 19:42 Message: Logged In: YES user_id=140558 I'm very busy but again will try to find some time to fix it. I'm using it every day without a glitch, even using the clause attributes like in the Complex example (new type of joins *toMany). I'll update it to latest SVN just in case this is the problem, I did it with that day's current. Please do not close it, I really intend to pass the tests, I'm already using it. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-09 19:11 Message: Logged In: YES user_id=4799 test_auto.py, for example fails: def test_dynamicJoin(self): col = KeyCol('personID', foreignKey='Person') Phone.sqlmeta.addColumn(col, changeSchema=True) join = MultipleJoin('Phone') Person.sqlmeta.addJoin(join) for phone in Phone.select('all'): if phone.phone.startswith('555'): phone.person = Person.selectBy(name='tim')[0] else: phone.person = Person.selectBy(name='bob')[0] l = [p.phone for p in Person.selectBy(name='tim')[0].phones] l.sort() E assert l == ['555-394-2930', '555-555-5555'] > assert [] == ['555-394-2930', '555-555-5555'] [sqlobject/tests/test_auto.py:61] ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-30 21:10 Message: Logged In: YES user_id=140558 I'll recheck it, it really passed all the tests applied to the latest svn. I tell you something tomorrow. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-30 21:07 Message: Logged In: YES user_id=140558 I'll recheck it, it really passed all the tests applied to the latest svn. I tell you something tomorrow. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-30 20:57 Message: Logged In: YES user_id=4799 test_auto.py, test_auto_old.py and test_basic.py failed. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-18 19:04 Message: Logged In: YES user_id=140558 This is the final patch against latest svn, it includes everything in one single patch. It passes the tests. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-18 16:17 Message: Logged In: YES user_id=140558 Ok, I have taken my time to understand pydist, test, etc, and here I am back with the working solution :) Now the resulting SQLobject passes all the tests. I attach an incremental patch so that you can see more clearly the changes done to fix the previous one. I've needed a new method in the Style class, instanceIDAttrToAttr, that is the complementary to the already known instanceAttrToIDAttr. If you need to transform back and forth field names, you need them both. I haven't tried to port it to the latest svn yet, this is against the same release than the first patch, but it should apply more or less clearly as this are very isolated areas in the code. When I do it I'll post it here. Sorry for the delay, it has not been easy for me to understand more deeply the code and, even less, to know how the tests work :) ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-03 15:18 Message: Logged In: YES user_id=140558 It fails because the test is not right, it still has the ID postfix hardcoded. My fault, I did no send a patch for tests. This is the piece that fails: # Select by usual way s = TestWorkKey.selectBy(composerID=c.id, title='Symphony No. 9') I have not looked at tests until now, but it looks like there should be tests for the different provides styles, in this case, if you accept the patch, at least a test for the LongStyle provided and for the current naming styles. I'll try to cook up something, but it can take a little time. Any guidelines will be appreciated (I've just read the docs ;) ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-03 14:23 Message: Logged In: YES user_id=4799 test_selectBy_foreignKey.py fails: def test1(): setupClass([TestComposerKey, TestWorkKey]) c = TestComposerKey(name='Mahler, Gustav') > w1 = TestWorkKey(composer=c, title='Symphony No. 9') [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/tests/test_selectBy_foreignKey.py:19] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def __init__(self, **kw): # The get() classmethod/constructor uses a magic keyword # argument when it wants an empty object, fetched from the # database. So we have nothing more to do in that case: if kw.has_key('_SO_fetch_no_create'): return post_funcs = [] self.sqlmeta.send(events.RowCreateSignal, kw, post_funcs) # Pass the connection object along if we were given one. if kw.has_key('connection'): self._connection = kw['connection'] self.sqlmeta._perConnection = True del kw['connection'] self._SO_writeLock = threading.Lock() if kw.has_key('id'): id = self.sqlmeta.idType(kw['id']) del kw['id'] else: id = None > self._create(id, **kw) [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/main.py:1210] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _create(self, id, **kw): self.sqlmeta._creating = True self._SO_createValues = {} self._SO_validatorState = SQLObjectState(self) # First we do a little fix-up on the keywords we were # passed: for column in self.sqlmeta.columnList: # Then we check if the column wasn't passed in, and # if not we try to get the default. if not kw.has_key(column.name) and not kw.has_key(column.foreignName): default = column.default # If we don't get it, it's an error: if default is NoDefault: E raise TypeError, "%s() did not get expected keyword argument %s" % (self.__class__.__name__, column.name) > TypeError: TestWorkKey() did not get expected keyword argument composerID [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/main.py:1231] - - - - - - - - - - - - - test1: recorded stdout - - - - - - - - - - - - - - 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/Query : CREATE TABLE test_composer_key ( id SERIAL PRIMARY KEY, name TEXT ) 1/QueryR : CREATE TABLE test_composer_key ( id SERIAL PRIMARY KEY, name TEXT ) 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/Query : CREATE TABLE test_work_key ( work_id SERIAL PRIMARY KEY, composer_id INT, title TEXT ) 1/QueryR : CREATE TABLE test_work_key ( work_id SERIAL PRIMARY KEY, composer_id INT, title TEXT ) 1/COMMIT : auto 1/Query : ALTER TABLE test_work_key ADD CONSTRAINT composer_id_exists FOREIGN KEY (composer_id) REFERENCES test_composer_key (id) 1/QueryR : ALTER TABLE test_work_key ADD CONSTRAINT composer_id_exists FOREIGN KEY (composer_id) REFERENCES test_composer_key (id) 1/COMMIT : auto 1/QueryIns: INSERT INTO test_composer_key (id, name) VALUES (1, 'Mahler, Gustav') 1/COMMIT : auto 1/QueryOne: SELECT name FROM test_composer_key WHERE id = 1 1/QueryR : SELECT name FROM test_composer_key WHERE id = 1 1/COMMIT : auto ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1353728&group_id=74338 |
|
From: <sub...@co...> - 2006-02-17 16:50:12
|
Author: phd
Date: 2006-02-17 09:50:00 -0700 (Fri, 17 Feb 2006)
New Revision: 1609
Modified:
SQLObject/trunk/sqlobject/tests/test_foreignKey.py
Log:
Fixed the test.
Modified: SQLObject/trunk/sqlobject/tests/test_foreignKey.py
===================================================================
--- SQLObject/trunk/sqlobject/tests/test_foreignKey.py 2006-02-17 15:51:50 UTC (rev 1608)
+++ SQLObject/trunk/sqlobject/tests/test_foreignKey.py 2006-02-17 16:50:00 UTC (rev 1609)
@@ -1,5 +1,6 @@
from sqlobject import *
from sqlobject.tests.dbtest import *
+from sqlobject.tests.dbtest import InstalledTestDatabase
class TestComposerKey(SQLObject):
name = StringCol()
@@ -38,5 +39,7 @@
assert s[0]==w2
def test2():
+ TestWorkKey ._connection = getConnection()
+ InstalledTestDatabase.drop(TestWorkKey)
setupClass([TestComposerKey, TestWorkKey2], force=True)
TestWorkKey2.sqlmeta.addColumn(ForeignKey('TestComposerKey'), changeSchema=True)
|
|
From: SourceForge.net <no...@so...> - 2006-02-17 16:40:04
|
Patches item #1353728, was opened at 2005-11-11 08:20 Message generated for change (Comment added) made by linux4u You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1353728&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Closed Resolution: Accepted Priority: 5 Submitted By: Pau Aliagas (linux4u) Assigned to: Oleg Broytmann (phd) Summary: define foreign keys in Style Initial Comment: I don't like to use attrID all along the code to access related tables, I want to be able use the nomeclature I like taking advantage of the nice Style idea. This is especially true when you create RelatedJoins when you use a nomeclature like I do (table.id_table), but it's the same for all the nomeclatures you can imagine. In styles.py it warns: def instanceAttrToIDAttr(self, attr): # @@: Right now, because of how names are created for foreign # keys, you can't really change this style. return attr + "ID" With this patch you can define how you want the foreign keys generated, they won't be mandatorily generated as attrID. Example: class LongStyle(Style): """ This style is derived from Style, that does not do any translation, but constructs the table ids like id_table. """ def instanceAttrToIDAttr(self, attr): return "id_" + attr def tableReference(self, table): # str.rsplit is python 2.4+ only if version_info >= (2, 4): return "id_" + table.rsplit(".", 1)[-1] else: return "id_" + rsplit(table, ".", 1)[-1] class mm_server(SQLObject): class sqlmeta: table = "smsarena.mm_server" style = LongStyle(longID = True) _connection = conn_smsarena server = StringCol(alternateID = True, varchar = True, length = 255, alternateMethodName = "by_server") tz = StringCol(length = 20, default = 'CET', notNone = True) conutry_code = StringCol(length = 2, varchar = False, default = '', notNone = True) # until now I had to do this # mm_server_aliases = SQLMultipleJoin("mm_server_alias", joinColumn = "mm_serverID", orderBy = "server") # now it's perfect! mm_server_aliases = SQLMultipleJoin("mm_server_alias", orderBy = "server") class mm_server_alias(SQLObject): class sqlmeta: table = "smsarena.mm_server_alias" style = LongStyle(longID = True) _connection = conn_smsarena # until now I had to do this # mm_server = ForeignKey("mm_server", dbName = "id_mm_server") mm_server = ForeignKey("mm_server") server = StringCol(alternateID = True, varchar = True, length = 255, alternateMethodName = "by_server") I hope it's clear :) Pau ---------------------------------------------------------------------- >Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 17:39 Message: Logged In: YES user_id=140558 This can be solve with a onliner in default style: if not name.endswith("ID")... IMHO doing addColumn(fieldID, ForeignKey..) is a mistake You should do addColumn(field, ForeignKey..) and style takes care of it. If you want I can submit this oneliner for 0.7 only and you reconsider ading it to 0.7. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 17:29 Message: Logged In: YES user_id=4799 Even that's a big change, too big for 0.7 bugfix. Don't hesitate to post patches or at least bug reports for other issues. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 17:12 Message: Logged In: YES user_id=140558 Answering your concerns about the API... The only change is the one I have explained when using addColumn(fieldID, ForeignKey..). If you put ID, the current default style rules would add it too, so you'd get fieldIDID. We could change the style rules and look at this case, but I think that the current behaviour (as it is now with the patch) is completly orthogonal and always acts the same way, no black magic required. For the rest this is a HUGE addition!! You don't need to worry anymore about namning styles, nothing is written in stone. the ID thing was everywhere in the code Combined with the other patch (select using the object, not the id), you can almost always avoid referring directly to foreign field names. I really feel much more comfortable with these changes applied, seeign fieldID in the code maed me feel that something was not competely right. Avoiding it makes the code look beautiful. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 17:06 Message: Logged In: YES user_id=4799 SUM() should return whtaver the DB returns. I think summing an INT column returns an int, summing a FLOAT column returns a float. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 16:59 Message: Logged In: YES user_id=140558 Ok, another test mistery solved: This is the culprit that test_SQLMultipleJoin.py fails: assert str(hibrid.fightersAsSResult.sum('power')) == '23' In pgsql hibrid.fightersAsSResult.sum('power') returns 23. In sqlite-3.1.2 and mysql-4.1 it returns 23.0. So we should either fix the test or the sum function. Fixing the test could be as easy as casting the float to int: assert str(int(hibrid.fightersAsSResult.sum('power'))) == '23' but I'mn not sure if this would hide a bug. Should sum return float or int? ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 16:55 Message: Logged In: YES user_id=4799 Yes, it works finally! Applied in the revision 1607. Thank you for the job! How much does it change the API? Does it have meaning to be applied to 0.7 branch? I actually applied it and it passed all tests, but I don't want to break API for 0.7.1. Will all old programs work? ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 16:49 Message: Logged In: YES user_id=140558 After fixing my patch (I'm sure it works now!!) I'm reviewing the tests that fail. See the attached file "failed tests 2006-01-17 version 1" for the tests an the detailed explanations. In summary: test_ForeignKey.py: you know about it, it fails in all the databases test_SQLMultipleJoin.py: I don't see why it fails, it fails in sqlite and mysql, not in pgsql * sqlite * my problem is that sqlite-3.1.2 does not support alter tabble ad column, so no problem. * mysql * test_datetime.py ---------------- to_python does not seem to work as expected. test_enum.py ------------ BLOB/TEXT column indexes require length in mysql I hope that this makes clear the current status. If you accept the current patch, maybe we could open another ticket with the current bugs in mysql and sqlite, as these are clearly separate issues. Thanks ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 14:26 Message: Logged In: YES user_id=140558 I've fixed the problems with addColumns and delColum, now it passes the tests (not the ones that fail I do not why). I've fixed the tests too: I think we should NOT add the columns with ID at the end as the style add it for you. Otherwise I should modify the sytle functions to conditionally check if they end in ID.... I don't think that it is ok, if we want that, we define anthjer style that removes double ID at the end. This is internal to the style and so should be kept. Hope it's ok now :) ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 14:01 Message: Logged In: YES user_id=140558 These are my versions (ignore my comment in the other patch ticket, my misake): mysql-4.1.16-1.FC4.1 postgresql-8.0.7-1.FC4.1 python-psycopg-1.1.21-1.fc4 python-sqlite-1.1.6-1 sqlite-3.1.2-3 ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 13:38 Message: Logged In: YES user_id=4799 Except for the problem i test_ForeignKey.py that I know about... others look pretty strange. Let look at the environment. What DB versions? MySQL, PgSQL, SQLite? Drivers versions? MySQLdb, psycopg, PySQLite? MyPostgres is 7.4, psycopg 1.1.21 and 2.0b5. PySQLite 1.1.7 and 2.1.3. A week ago I upgarded to SQLite 3.3.3 and PySQLite 2.1.3; that eliminated some minor problems with patches I have had with SQLIte 2.8.0 and PySQLite 2.1.0. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 13:11 Message: Logged In: YES user_id=140558 Ok, plain SQLObject from SVN now, no patch. There are tests that fail for me in current SQLObject in mysql, postgres and sqlite. I attach them all. This is a fully updated Fedora 4. I've made the tests in mysql and there are some thet do not pass. I enclose the results and a file where I comment why the fail and a possible solution. The tests that fail in postgres and sqlite are the ones I've already reported (mnore or less). Any help? ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 10:22 Message: Logged In: YES user_id=4799 No, the latest SQLObject passes all tests (how would I commit your other patch if a test fail?) except for minor glitch in test_ForeignKey.py which I'm going to resolve RSN. test_auto.py certainly pass. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 10:13 Message: Logged In: YES user_id=140558 I've run the test with the latest SQLObject (no extra patches) and the tests fail too, at least they fail when I run them. As I explained before, there's something wrong when adding columns to sqlite, it fails and all the tests that depend on the added columns fail too. Does it happen to you too? ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-16 16:16 Message: Logged In: YES user_id=4799 These tests fail in both Postgres and SQLite. Two major backends (of 3) for SQLObject. If the problem is in tests you can patch tests, too... test_auto.py: def test_dynamicJoin(self): col = KeyCol('personID', foreignKey='Person') Phone.sqlmeta.addColumn(col, changeSchema=True) join = MultipleJoin('Phone') Person.sqlmeta.addJoin(join) for phone in Phone.select('all'): if phone.phone.startswith('555'): phone.person = Person.selectBy(name='tim')[0] else: phone.person = Person.selectBy(name='bob')[0] > l = [p.phone for p in Person.selectBy(name='tim')[0].phones] [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/test_auto.py:59] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > [failure to get at sourcelines from <TracebackEntry /home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/<string>:1>] [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/<string>:1] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def performJoin(self, inst): ids = inst._connection._SO_selectJoin( self.otherClass, self.joinColumn, > inst.id) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/joins.py:144] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _SO_selectJoin(self, soClass, column, value): return self.queryAll("SELECT %s FROM %s WHERE %s = %s" % (soClass.sqlmeta.idName, soClass.sqlmeta.table, column, > self.sqlrepr(value))) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:652] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def queryAll(self, s): > return self._runWithConnection(self._queryAll, s) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:327] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _runWithConnection(self, meth, *args): conn = self.getConnection() try: > val = meth(conn, *args) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:228] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _queryAll(self, conn, s): if self.debug: self.printDebug(conn, s, 'QueryAll') c = conn.cursor() > self._executeRetry(conn, c, s) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:320] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _executeRetry(self, conn, cursor, query): if self.debug: self.printDebug(conn, query, 'QueryR') E return cursor.execute(query) > OperationalError: no such column: person_id [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:306] - - - - - - - - - - - test_dynamicJoin: recorded stdout - - - - - - - - - - - 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/Query : DELETE FROM person 1/QueryR : DELETE FROM person 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/Query : DELETE FROM phone 1/QueryR : DELETE FROM phone 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('jane') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 1 1/QueryR : SELECT name_col FROM person WHERE id = 1 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('tim') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 2 1/QueryR : SELECT name_col FROM person WHERE id = 2 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('bob') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 3 1/QueryR : SELECT name_col FROM person WHERE id = 3 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('jake') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 4 1/QueryR : SELECT name_col FROM person WHERE id = 4 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('555-555-5555') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 1 1/QueryR : SELECT phone FROM phone WHERE id = 1 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('555-394-2930') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 2 1/QueryR : SELECT phone FROM phone WHERE id = 2 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('444-382-4854') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 3 1/QueryR : SELECT phone FROM phone WHERE id = 3 1/COMMIT : auto 1/Query : ALTER TABLE phone ADD COLUMN person_i_d_id INT 1/QueryR : ALTER TABLE phone ADD COLUMN person_i_d_id INT 1/COMMIT : auto 1/Select : SELECT phone.id, phone.phone, phone.person_i_d_id FROM phone WHERE 1 = 1 ORDER BY phone 1/QueryR : SELECT phone.id, phone.phone, phone.person_i_d_id FROM phone WHERE 1 = 1 ORDER BY phone 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'bob' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'bob' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/QueryAll: SELECT id FROM phone WHERE person_id = 2 1/QueryR : SELECT id FROM phone WHERE person_id = 2 1/COMMIT : auto ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-15 16:54 Message: Logged In: YES user_id=140558 Ok, here I go again. I've fixed a small bug: the name of the field was not porperly set when using Key(foreignKey... instead of ForeignKey. This fixes test_basic. And I think that there is nothing else to fix, I'm probably wrong, but I'll explain it hera. test_auto_old.py... FAIL test_auto.py... FAIL test_foreignKey.py... FAIL These tests fail because sqlite is failing when adding columns. In mysql it does not fail. I do not think it's this patch fault. And finally: test_SQLMultipleJoin.py... FAIL E assert str(hibrid.fightersAsSResult.sum('power')) == '23' > assert '23.0' == '23' + where '23.0' = str(23.0) + where 23.0 = <Race 3 name="'hibrid (human wi...'">.fightersAsSResult.sum('power') Again this is an error in the test. Please let me know if it can go in now :) If you can have a quick look at it better, it takes time to restart ths tests, I'd rather do it before I move on to another thing. Thanks Pau ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-14 10:05 Message: Logged In: YES user_id=140558 Oleg, I've posted to the list because I run the tests and pass. I'm sure I'm doing something wrong but I don't see what. I lost more than 3 hours yesterday just trying to run te tests :( I printed things in dbtest.py and say that TESTDB did not change anything. I chenged manually conftest.py because I ahd a message that yoiu need sqlite2 for memory databases, but still I'm not sure everything works becasue I pass al the tests. Can you help me, I want to close this patch soon and move to other improvements but this is being much more difficult than it should. Thanks a lot Pau ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-09 17:42 Message: Logged In: YES user_id=140558 I'm very busy but again will try to find some time to fix it. I'm using it every day without a glitch, even using the clause attributes like in the Complex example (new type of joins *toMany). I'll update it to latest SVN just in case this is the problem, I did it with that day's current. Please do not close it, I really intend to pass the tests, I'm already using it. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-09 17:11 Message: Logged In: YES user_id=4799 test_auto.py, for example fails: def test_dynamicJoin(self): col = KeyCol('personID', foreignKey='Person') Phone.sqlmeta.addColumn(col, changeSchema=True) join = MultipleJoin('Phone') Person.sqlmeta.addJoin(join) for phone in Phone.select('all'): if phone.phone.startswith('555'): phone.person = Person.selectBy(name='tim')[0] else: phone.person = Person.selectBy(name='bob')[0] l = [p.phone for p in Person.selectBy(name='tim')[0].phones] l.sort() E assert l == ['555-394-2930', '555-555-5555'] > assert [] == ['555-394-2930', '555-555-5555'] [sqlobject/tests/test_auto.py:61] ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-30 19:10 Message: Logged In: YES user_id=140558 I'll recheck it, it really passed all the tests applied to the latest svn. I tell you something tomorrow. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-30 19:07 Message: Logged In: YES user_id=140558 I'll recheck it, it really passed all the tests applied to the latest svn. I tell you something tomorrow. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-30 18:57 Message: Logged In: YES user_id=4799 test_auto.py, test_auto_old.py and test_basic.py failed. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-18 17:04 Message: Logged In: YES user_id=140558 This is the final patch against latest svn, it includes everything in one single patch. It passes the tests. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-18 14:17 Message: Logged In: YES user_id=140558 Ok, I have taken my time to understand pydist, test, etc, and here I am back with the working solution :) Now the resulting SQLobject passes all the tests. I attach an incremental patch so that you can see more clearly the changes done to fix the previous one. I've needed a new method in the Style class, instanceIDAttrToAttr, that is the complementary to the already known instanceAttrToIDAttr. If you need to transform back and forth field names, you need them both. I haven't tried to port it to the latest svn yet, this is against the same release than the first patch, but it should apply more or less clearly as this are very isolated areas in the code. When I do it I'll post it here. Sorry for the delay, it has not been easy for me to understand more deeply the code and, even less, to know how the tests work :) ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-03 13:18 Message: Logged In: YES user_id=140558 It fails because the test is not right, it still has the ID postfix hardcoded. My fault, I did no send a patch for tests. This is the piece that fails: # Select by usual way s = TestWorkKey.selectBy(composerID=c.id, title='Symphony No. 9') I have not looked at tests until now, but it looks like there should be tests for the different provides styles, in this case, if you accept the patch, at least a test for the LongStyle provided and for the current naming styles. I'll try to cook up something, but it can take a little time. Any guidelines will be appreciated (I've just read the docs ;) ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-03 12:23 Message: Logged In: YES user_id=4799 test_selectBy_foreignKey.py fails: def test1(): setupClass([TestComposerKey, TestWorkKey]) c = TestComposerKey(name='Mahler, Gustav') > w1 = TestWorkKey(composer=c, title='Symphony No. 9') [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/tests/test_selectBy_foreignKey.py:19] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def __init__(self, **kw): # The get() classmethod/constructor uses a magic keyword # argument when it wants an empty object, fetched from the # database. So we have nothing more to do in that case: if kw.has_key('_SO_fetch_no_create'): return post_funcs = [] self.sqlmeta.send(events.RowCreateSignal, kw, post_funcs) # Pass the connection object along if we were given one. if kw.has_key('connection'): self._connection = kw['connection'] self.sqlmeta._perConnection = True del kw['connection'] self._SO_writeLock = threading.Lock() if kw.has_key('id'): id = self.sqlmeta.idType(kw['id']) del kw['id'] else: id = None > self._create(id, **kw) [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/main.py:1210] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _create(self, id, **kw): self.sqlmeta._creating = True self._SO_createValues = {} self._SO_validatorState = SQLObjectState(self) # First we do a little fix-up on the keywords we were # passed: for column in self.sqlmeta.columnList: # Then we check if the column wasn't passed in, and # if not we try to get the default. if not kw.has_key(column.name) and not kw.has_key(column.foreignName): default = column.default # If we don't get it, it's an error: if default is NoDefault: E raise TypeError, "%s() did not get expected keyword argument %s" % (self.__class__.__name__, column.name) > TypeError: TestWorkKey() did not get expected keyword argument composerID [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/main.py:1231] - - - - - - - - - - - - - test1: recorded stdout - - - - - - - - - - - - - - 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/Query : CREATE TABLE test_composer_key ( id SERIAL PRIMARY KEY, name TEXT ) 1/QueryR : CREATE TABLE test_composer_key ( id SERIAL PRIMARY KEY, name TEXT ) 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/Query : CREATE TABLE test_work_key ( work_id SERIAL PRIMARY KEY, composer_id INT, title TEXT ) 1/QueryR : CREATE TABLE test_work_key ( work_id SERIAL PRIMARY KEY, composer_id INT, title TEXT ) 1/COMMIT : auto 1/Query : ALTER TABLE test_work_key ADD CONSTRAINT composer_id_exists FOREIGN KEY (composer_id) REFERENCES test_composer_key (id) 1/QueryR : ALTER TABLE test_work_key ADD CONSTRAINT composer_id_exists FOREIGN KEY (composer_id) REFERENCES test_composer_key (id) 1/COMMIT : auto 1/QueryIns: INSERT INTO test_composer_key (id, name) VALUES (1, 'Mahler, Gustav') 1/COMMIT : auto 1/QueryOne: SELECT name FROM test_composer_key WHERE id = 1 1/QueryR : SELECT name FROM test_composer_key WHERE id = 1 1/COMMIT : auto ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1353728&group_id=74338 |
|
From: SourceForge.net <no...@so...> - 2006-02-17 16:29:12
|
Patches item #1353728, was opened at 2005-11-11 10:20 Message generated for change (Comment added) made by phd You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1353728&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None >Status: Closed >Resolution: Accepted Priority: 5 Submitted By: Pau Aliagas (linux4u) Assigned to: Oleg Broytmann (phd) Summary: define foreign keys in Style Initial Comment: I don't like to use attrID all along the code to access related tables, I want to be able use the nomeclature I like taking advantage of the nice Style idea. This is especially true when you create RelatedJoins when you use a nomeclature like I do (table.id_table), but it's the same for all the nomeclatures you can imagine. In styles.py it warns: def instanceAttrToIDAttr(self, attr): # @@: Right now, because of how names are created for foreign # keys, you can't really change this style. return attr + "ID" With this patch you can define how you want the foreign keys generated, they won't be mandatorily generated as attrID. Example: class LongStyle(Style): """ This style is derived from Style, that does not do any translation, but constructs the table ids like id_table. """ def instanceAttrToIDAttr(self, attr): return "id_" + attr def tableReference(self, table): # str.rsplit is python 2.4+ only if version_info >= (2, 4): return "id_" + table.rsplit(".", 1)[-1] else: return "id_" + rsplit(table, ".", 1)[-1] class mm_server(SQLObject): class sqlmeta: table = "smsarena.mm_server" style = LongStyle(longID = True) _connection = conn_smsarena server = StringCol(alternateID = True, varchar = True, length = 255, alternateMethodName = "by_server") tz = StringCol(length = 20, default = 'CET', notNone = True) conutry_code = StringCol(length = 2, varchar = False, default = '', notNone = True) # until now I had to do this # mm_server_aliases = SQLMultipleJoin("mm_server_alias", joinColumn = "mm_serverID", orderBy = "server") # now it's perfect! mm_server_aliases = SQLMultipleJoin("mm_server_alias", orderBy = "server") class mm_server_alias(SQLObject): class sqlmeta: table = "smsarena.mm_server_alias" style = LongStyle(longID = True) _connection = conn_smsarena # until now I had to do this # mm_server = ForeignKey("mm_server", dbName = "id_mm_server") mm_server = ForeignKey("mm_server") server = StringCol(alternateID = True, varchar = True, length = 255, alternateMethodName = "by_server") I hope it's clear :) Pau ---------------------------------------------------------------------- >Comment By: Oleg Broytmann (phd) Date: 2006-02-17 19:29 Message: Logged In: YES user_id=4799 Even that's a big change, too big for 0.7 bugfix. Don't hesitate to post patches or at least bug reports for other issues. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 19:12 Message: Logged In: YES user_id=140558 Answering your concerns about the API... The only change is the one I have explained when using addColumn(fieldID, ForeignKey..). If you put ID, the current default style rules would add it too, so you'd get fieldIDID. We could change the style rules and look at this case, but I think that the current behaviour (as it is now with the patch) is completly orthogonal and always acts the same way, no black magic required. For the rest this is a HUGE addition!! You don't need to worry anymore about namning styles, nothing is written in stone. the ID thing was everywhere in the code Combined with the other patch (select using the object, not the id), you can almost always avoid referring directly to foreign field names. I really feel much more comfortable with these changes applied, seeign fieldID in the code maed me feel that something was not competely right. Avoiding it makes the code look beautiful. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 19:06 Message: Logged In: YES user_id=4799 SUM() should return whtaver the DB returns. I think summing an INT column returns an int, summing a FLOAT column returns a float. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 18:59 Message: Logged In: YES user_id=140558 Ok, another test mistery solved: This is the culprit that test_SQLMultipleJoin.py fails: assert str(hibrid.fightersAsSResult.sum('power')) == '23' In pgsql hibrid.fightersAsSResult.sum('power') returns 23. In sqlite-3.1.2 and mysql-4.1 it returns 23.0. So we should either fix the test or the sum function. Fixing the test could be as easy as casting the float to int: assert str(int(hibrid.fightersAsSResult.sum('power'))) == '23' but I'mn not sure if this would hide a bug. Should sum return float or int? ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 18:55 Message: Logged In: YES user_id=4799 Yes, it works finally! Applied in the revision 1607. Thank you for the job! How much does it change the API? Does it have meaning to be applied to 0.7 branch? I actually applied it and it passed all tests, but I don't want to break API for 0.7.1. Will all old programs work? ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 18:49 Message: Logged In: YES user_id=140558 After fixing my patch (I'm sure it works now!!) I'm reviewing the tests that fail. See the attached file "failed tests 2006-01-17 version 1" for the tests an the detailed explanations. In summary: test_ForeignKey.py: you know about it, it fails in all the databases test_SQLMultipleJoin.py: I don't see why it fails, it fails in sqlite and mysql, not in pgsql * sqlite * my problem is that sqlite-3.1.2 does not support alter tabble ad column, so no problem. * mysql * test_datetime.py ---------------- to_python does not seem to work as expected. test_enum.py ------------ BLOB/TEXT column indexes require length in mysql I hope that this makes clear the current status. If you accept the current patch, maybe we could open another ticket with the current bugs in mysql and sqlite, as these are clearly separate issues. Thanks ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 16:26 Message: Logged In: YES user_id=140558 I've fixed the problems with addColumns and delColum, now it passes the tests (not the ones that fail I do not why). I've fixed the tests too: I think we should NOT add the columns with ID at the end as the style add it for you. Otherwise I should modify the sytle functions to conditionally check if they end in ID.... I don't think that it is ok, if we want that, we define anthjer style that removes double ID at the end. This is internal to the style and so should be kept. Hope it's ok now :) ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 16:01 Message: Logged In: YES user_id=140558 These are my versions (ignore my comment in the other patch ticket, my misake): mysql-4.1.16-1.FC4.1 postgresql-8.0.7-1.FC4.1 python-psycopg-1.1.21-1.fc4 python-sqlite-1.1.6-1 sqlite-3.1.2-3 ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 15:38 Message: Logged In: YES user_id=4799 Except for the problem i test_ForeignKey.py that I know about... others look pretty strange. Let look at the environment. What DB versions? MySQL, PgSQL, SQLite? Drivers versions? MySQLdb, psycopg, PySQLite? MyPostgres is 7.4, psycopg 1.1.21 and 2.0b5. PySQLite 1.1.7 and 2.1.3. A week ago I upgarded to SQLite 3.3.3 and PySQLite 2.1.3; that eliminated some minor problems with patches I have had with SQLIte 2.8.0 and PySQLite 2.1.0. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 15:11 Message: Logged In: YES user_id=140558 Ok, plain SQLObject from SVN now, no patch. There are tests that fail for me in current SQLObject in mysql, postgres and sqlite. I attach them all. This is a fully updated Fedora 4. I've made the tests in mysql and there are some thet do not pass. I enclose the results and a file where I comment why the fail and a possible solution. The tests that fail in postgres and sqlite are the ones I've already reported (mnore or less). Any help? ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 12:22 Message: Logged In: YES user_id=4799 No, the latest SQLObject passes all tests (how would I commit your other patch if a test fail?) except for minor glitch in test_ForeignKey.py which I'm going to resolve RSN. test_auto.py certainly pass. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 12:13 Message: Logged In: YES user_id=140558 I've run the test with the latest SQLObject (no extra patches) and the tests fail too, at least they fail when I run them. As I explained before, there's something wrong when adding columns to sqlite, it fails and all the tests that depend on the added columns fail too. Does it happen to you too? ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-16 18:16 Message: Logged In: YES user_id=4799 These tests fail in both Postgres and SQLite. Two major backends (of 3) for SQLObject. If the problem is in tests you can patch tests, too... test_auto.py: def test_dynamicJoin(self): col = KeyCol('personID', foreignKey='Person') Phone.sqlmeta.addColumn(col, changeSchema=True) join = MultipleJoin('Phone') Person.sqlmeta.addJoin(join) for phone in Phone.select('all'): if phone.phone.startswith('555'): phone.person = Person.selectBy(name='tim')[0] else: phone.person = Person.selectBy(name='bob')[0] > l = [p.phone for p in Person.selectBy(name='tim')[0].phones] [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/test_auto.py:59] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > [failure to get at sourcelines from <TracebackEntry /home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/<string>:1>] [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/<string>:1] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def performJoin(self, inst): ids = inst._connection._SO_selectJoin( self.otherClass, self.joinColumn, > inst.id) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/joins.py:144] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _SO_selectJoin(self, soClass, column, value): return self.queryAll("SELECT %s FROM %s WHERE %s = %s" % (soClass.sqlmeta.idName, soClass.sqlmeta.table, column, > self.sqlrepr(value))) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:652] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def queryAll(self, s): > return self._runWithConnection(self._queryAll, s) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:327] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _runWithConnection(self, meth, *args): conn = self.getConnection() try: > val = meth(conn, *args) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:228] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _queryAll(self, conn, s): if self.debug: self.printDebug(conn, s, 'QueryAll') c = conn.cursor() > self._executeRetry(conn, c, s) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:320] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _executeRetry(self, conn, cursor, query): if self.debug: self.printDebug(conn, query, 'QueryR') E return cursor.execute(query) > OperationalError: no such column: person_id [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:306] - - - - - - - - - - - test_dynamicJoin: recorded stdout - - - - - - - - - - - 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/Query : DELETE FROM person 1/QueryR : DELETE FROM person 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/Query : DELETE FROM phone 1/QueryR : DELETE FROM phone 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('jane') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 1 1/QueryR : SELECT name_col FROM person WHERE id = 1 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('tim') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 2 1/QueryR : SELECT name_col FROM person WHERE id = 2 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('bob') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 3 1/QueryR : SELECT name_col FROM person WHERE id = 3 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('jake') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 4 1/QueryR : SELECT name_col FROM person WHERE id = 4 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('555-555-5555') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 1 1/QueryR : SELECT phone FROM phone WHERE id = 1 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('555-394-2930') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 2 1/QueryR : SELECT phone FROM phone WHERE id = 2 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('444-382-4854') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 3 1/QueryR : SELECT phone FROM phone WHERE id = 3 1/COMMIT : auto 1/Query : ALTER TABLE phone ADD COLUMN person_i_d_id INT 1/QueryR : ALTER TABLE phone ADD COLUMN person_i_d_id INT 1/COMMIT : auto 1/Select : SELECT phone.id, phone.phone, phone.person_i_d_id FROM phone WHERE 1 = 1 ORDER BY phone 1/QueryR : SELECT phone.id, phone.phone, phone.person_i_d_id FROM phone WHERE 1 = 1 ORDER BY phone 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'bob' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'bob' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/QueryAll: SELECT id FROM phone WHERE person_id = 2 1/QueryR : SELECT id FROM phone WHERE person_id = 2 1/COMMIT : auto ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-15 18:54 Message: Logged In: YES user_id=140558 Ok, here I go again. I've fixed a small bug: the name of the field was not porperly set when using Key(foreignKey... instead of ForeignKey. This fixes test_basic. And I think that there is nothing else to fix, I'm probably wrong, but I'll explain it hera. test_auto_old.py... FAIL test_auto.py... FAIL test_foreignKey.py... FAIL These tests fail because sqlite is failing when adding columns. In mysql it does not fail. I do not think it's this patch fault. And finally: test_SQLMultipleJoin.py... FAIL E assert str(hibrid.fightersAsSResult.sum('power')) == '23' > assert '23.0' == '23' + where '23.0' = str(23.0) + where 23.0 = <Race 3 name="'hibrid (human wi...'">.fightersAsSResult.sum('power') Again this is an error in the test. Please let me know if it can go in now :) If you can have a quick look at it better, it takes time to restart ths tests, I'd rather do it before I move on to another thing. Thanks Pau ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-14 12:05 Message: Logged In: YES user_id=140558 Oleg, I've posted to the list because I run the tests and pass. I'm sure I'm doing something wrong but I don't see what. I lost more than 3 hours yesterday just trying to run te tests :( I printed things in dbtest.py and say that TESTDB did not change anything. I chenged manually conftest.py because I ahd a message that yoiu need sqlite2 for memory databases, but still I'm not sure everything works becasue I pass al the tests. Can you help me, I want to close this patch soon and move to other improvements but this is being much more difficult than it should. Thanks a lot Pau ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-09 19:42 Message: Logged In: YES user_id=140558 I'm very busy but again will try to find some time to fix it. I'm using it every day without a glitch, even using the clause attributes like in the Complex example (new type of joins *toMany). I'll update it to latest SVN just in case this is the problem, I did it with that day's current. Please do not close it, I really intend to pass the tests, I'm already using it. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-09 19:11 Message: Logged In: YES user_id=4799 test_auto.py, for example fails: def test_dynamicJoin(self): col = KeyCol('personID', foreignKey='Person') Phone.sqlmeta.addColumn(col, changeSchema=True) join = MultipleJoin('Phone') Person.sqlmeta.addJoin(join) for phone in Phone.select('all'): if phone.phone.startswith('555'): phone.person = Person.selectBy(name='tim')[0] else: phone.person = Person.selectBy(name='bob')[0] l = [p.phone for p in Person.selectBy(name='tim')[0].phones] l.sort() E assert l == ['555-394-2930', '555-555-5555'] > assert [] == ['555-394-2930', '555-555-5555'] [sqlobject/tests/test_auto.py:61] ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-30 21:10 Message: Logged In: YES user_id=140558 I'll recheck it, it really passed all the tests applied to the latest svn. I tell you something tomorrow. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-30 21:07 Message: Logged In: YES user_id=140558 I'll recheck it, it really passed all the tests applied to the latest svn. I tell you something tomorrow. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-30 20:57 Message: Logged In: YES user_id=4799 test_auto.py, test_auto_old.py and test_basic.py failed. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-18 19:04 Message: Logged In: YES user_id=140558 This is the final patch against latest svn, it includes everything in one single patch. It passes the tests. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-18 16:17 Message: Logged In: YES user_id=140558 Ok, I have taken my time to understand pydist, test, etc, and here I am back with the working solution :) Now the resulting SQLobject passes all the tests. I attach an incremental patch so that you can see more clearly the changes done to fix the previous one. I've needed a new method in the Style class, instanceIDAttrToAttr, that is the complementary to the already known instanceAttrToIDAttr. If you need to transform back and forth field names, you need them both. I haven't tried to port it to the latest svn yet, this is against the same release than the first patch, but it should apply more or less clearly as this are very isolated areas in the code. When I do it I'll post it here. Sorry for the delay, it has not been easy for me to understand more deeply the code and, even less, to know how the tests work :) ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-03 15:18 Message: Logged In: YES user_id=140558 It fails because the test is not right, it still has the ID postfix hardcoded. My fault, I did no send a patch for tests. This is the piece that fails: # Select by usual way s = TestWorkKey.selectBy(composerID=c.id, title='Symphony No. 9') I have not looked at tests until now, but it looks like there should be tests for the different provides styles, in this case, if you accept the patch, at least a test for the LongStyle provided and for the current naming styles. I'll try to cook up something, but it can take a little time. Any guidelines will be appreciated (I've just read the docs ;) ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-03 14:23 Message: Logged In: YES user_id=4799 test_selectBy_foreignKey.py fails: def test1(): setupClass([TestComposerKey, TestWorkKey]) c = TestComposerKey(name='Mahler, Gustav') > w1 = TestWorkKey(composer=c, title='Symphony No. 9') [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/tests/test_selectBy_foreignKey.py:19] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def __init__(self, **kw): # The get() classmethod/constructor uses a magic keyword # argument when it wants an empty object, fetched from the # database. So we have nothing more to do in that case: if kw.has_key('_SO_fetch_no_create'): return post_funcs = [] self.sqlmeta.send(events.RowCreateSignal, kw, post_funcs) # Pass the connection object along if we were given one. if kw.has_key('connection'): self._connection = kw['connection'] self.sqlmeta._perConnection = True del kw['connection'] self._SO_writeLock = threading.Lock() if kw.has_key('id'): id = self.sqlmeta.idType(kw['id']) del kw['id'] else: id = None > self._create(id, **kw) [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/main.py:1210] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _create(self, id, **kw): self.sqlmeta._creating = True self._SO_createValues = {} self._SO_validatorState = SQLObjectState(self) # First we do a little fix-up on the keywords we were # passed: for column in self.sqlmeta.columnList: # Then we check if the column wasn't passed in, and # if not we try to get the default. if not kw.has_key(column.name) and not kw.has_key(column.foreignName): default = column.default # If we don't get it, it's an error: if default is NoDefault: E raise TypeError, "%s() did not get expected keyword argument %s" % (self.__class__.__name__, column.name) > TypeError: TestWorkKey() did not get expected keyword argument composerID [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/main.py:1231] - - - - - - - - - - - - - test1: recorded stdout - - - - - - - - - - - - - - 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/Query : CREATE TABLE test_composer_key ( id SERIAL PRIMARY KEY, name TEXT ) 1/QueryR : CREATE TABLE test_composer_key ( id SERIAL PRIMARY KEY, name TEXT ) 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/Query : CREATE TABLE test_work_key ( work_id SERIAL PRIMARY KEY, composer_id INT, title TEXT ) 1/QueryR : CREATE TABLE test_work_key ( work_id SERIAL PRIMARY KEY, composer_id INT, title TEXT ) 1/COMMIT : auto 1/Query : ALTER TABLE test_work_key ADD CONSTRAINT composer_id_exists FOREIGN KEY (composer_id) REFERENCES test_composer_key (id) 1/QueryR : ALTER TABLE test_work_key ADD CONSTRAINT composer_id_exists FOREIGN KEY (composer_id) REFERENCES test_composer_key (id) 1/COMMIT : auto 1/QueryIns: INSERT INTO test_composer_key (id, name) VALUES (1, 'Mahler, Gustav') 1/COMMIT : auto 1/QueryOne: SELECT name FROM test_composer_key WHERE id = 1 1/QueryR : SELECT name FROM test_composer_key WHERE id = 1 1/COMMIT : auto ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1353728&group_id=74338 |
|
From: SourceForge.net <no...@so...> - 2006-02-17 16:12:41
|
Patches item #1353728, was opened at 2005-11-11 08:20 Message generated for change (Comment added) made by linux4u You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1353728&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open >Resolution: Invalid Priority: 5 Submitted By: Pau Aliagas (linux4u) Assigned to: Oleg Broytmann (phd) Summary: define foreign keys in Style Initial Comment: I don't like to use attrID all along the code to access related tables, I want to be able use the nomeclature I like taking advantage of the nice Style idea. This is especially true when you create RelatedJoins when you use a nomeclature like I do (table.id_table), but it's the same for all the nomeclatures you can imagine. In styles.py it warns: def instanceAttrToIDAttr(self, attr): # @@: Right now, because of how names are created for foreign # keys, you can't really change this style. return attr + "ID" With this patch you can define how you want the foreign keys generated, they won't be mandatorily generated as attrID. Example: class LongStyle(Style): """ This style is derived from Style, that does not do any translation, but constructs the table ids like id_table. """ def instanceAttrToIDAttr(self, attr): return "id_" + attr def tableReference(self, table): # str.rsplit is python 2.4+ only if version_info >= (2, 4): return "id_" + table.rsplit(".", 1)[-1] else: return "id_" + rsplit(table, ".", 1)[-1] class mm_server(SQLObject): class sqlmeta: table = "smsarena.mm_server" style = LongStyle(longID = True) _connection = conn_smsarena server = StringCol(alternateID = True, varchar = True, length = 255, alternateMethodName = "by_server") tz = StringCol(length = 20, default = 'CET', notNone = True) conutry_code = StringCol(length = 2, varchar = False, default = '', notNone = True) # until now I had to do this # mm_server_aliases = SQLMultipleJoin("mm_server_alias", joinColumn = "mm_serverID", orderBy = "server") # now it's perfect! mm_server_aliases = SQLMultipleJoin("mm_server_alias", orderBy = "server") class mm_server_alias(SQLObject): class sqlmeta: table = "smsarena.mm_server_alias" style = LongStyle(longID = True) _connection = conn_smsarena # until now I had to do this # mm_server = ForeignKey("mm_server", dbName = "id_mm_server") mm_server = ForeignKey("mm_server") server = StringCol(alternateID = True, varchar = True, length = 255, alternateMethodName = "by_server") I hope it's clear :) Pau ---------------------------------------------------------------------- >Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 17:12 Message: Logged In: YES user_id=140558 Answering your concerns about the API... The only change is the one I have explained when using addColumn(fieldID, ForeignKey..). If you put ID, the current default style rules would add it too, so you'd get fieldIDID. We could change the style rules and look at this case, but I think that the current behaviour (as it is now with the patch) is completly orthogonal and always acts the same way, no black magic required. For the rest this is a HUGE addition!! You don't need to worry anymore about namning styles, nothing is written in stone. the ID thing was everywhere in the code Combined with the other patch (select using the object, not the id), you can almost always avoid referring directly to foreign field names. I really feel much more comfortable with these changes applied, seeign fieldID in the code maed me feel that something was not competely right. Avoiding it makes the code look beautiful. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 17:06 Message: Logged In: YES user_id=4799 SUM() should return whtaver the DB returns. I think summing an INT column returns an int, summing a FLOAT column returns a float. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 16:59 Message: Logged In: YES user_id=140558 Ok, another test mistery solved: This is the culprit that test_SQLMultipleJoin.py fails: assert str(hibrid.fightersAsSResult.sum('power')) == '23' In pgsql hibrid.fightersAsSResult.sum('power') returns 23. In sqlite-3.1.2 and mysql-4.1 it returns 23.0. So we should either fix the test or the sum function. Fixing the test could be as easy as casting the float to int: assert str(int(hibrid.fightersAsSResult.sum('power'))) == '23' but I'mn not sure if this would hide a bug. Should sum return float or int? ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 16:55 Message: Logged In: YES user_id=4799 Yes, it works finally! Applied in the revision 1607. Thank you for the job! How much does it change the API? Does it have meaning to be applied to 0.7 branch? I actually applied it and it passed all tests, but I don't want to break API for 0.7.1. Will all old programs work? ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 16:49 Message: Logged In: YES user_id=140558 After fixing my patch (I'm sure it works now!!) I'm reviewing the tests that fail. See the attached file "failed tests 2006-01-17 version 1" for the tests an the detailed explanations. In summary: test_ForeignKey.py: you know about it, it fails in all the databases test_SQLMultipleJoin.py: I don't see why it fails, it fails in sqlite and mysql, not in pgsql * sqlite * my problem is that sqlite-3.1.2 does not support alter tabble ad column, so no problem. * mysql * test_datetime.py ---------------- to_python does not seem to work as expected. test_enum.py ------------ BLOB/TEXT column indexes require length in mysql I hope that this makes clear the current status. If you accept the current patch, maybe we could open another ticket with the current bugs in mysql and sqlite, as these are clearly separate issues. Thanks ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 14:26 Message: Logged In: YES user_id=140558 I've fixed the problems with addColumns and delColum, now it passes the tests (not the ones that fail I do not why). I've fixed the tests too: I think we should NOT add the columns with ID at the end as the style add it for you. Otherwise I should modify the sytle functions to conditionally check if they end in ID.... I don't think that it is ok, if we want that, we define anthjer style that removes double ID at the end. This is internal to the style and so should be kept. Hope it's ok now :) ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 14:01 Message: Logged In: YES user_id=140558 These are my versions (ignore my comment in the other patch ticket, my misake): mysql-4.1.16-1.FC4.1 postgresql-8.0.7-1.FC4.1 python-psycopg-1.1.21-1.fc4 python-sqlite-1.1.6-1 sqlite-3.1.2-3 ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 13:38 Message: Logged In: YES user_id=4799 Except for the problem i test_ForeignKey.py that I know about... others look pretty strange. Let look at the environment. What DB versions? MySQL, PgSQL, SQLite? Drivers versions? MySQLdb, psycopg, PySQLite? MyPostgres is 7.4, psycopg 1.1.21 and 2.0b5. PySQLite 1.1.7 and 2.1.3. A week ago I upgarded to SQLite 3.3.3 and PySQLite 2.1.3; that eliminated some minor problems with patches I have had with SQLIte 2.8.0 and PySQLite 2.1.0. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 13:11 Message: Logged In: YES user_id=140558 Ok, plain SQLObject from SVN now, no patch. There are tests that fail for me in current SQLObject in mysql, postgres and sqlite. I attach them all. This is a fully updated Fedora 4. I've made the tests in mysql and there are some thet do not pass. I enclose the results and a file where I comment why the fail and a possible solution. The tests that fail in postgres and sqlite are the ones I've already reported (mnore or less). Any help? ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 10:22 Message: Logged In: YES user_id=4799 No, the latest SQLObject passes all tests (how would I commit your other patch if a test fail?) except for minor glitch in test_ForeignKey.py which I'm going to resolve RSN. test_auto.py certainly pass. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 10:13 Message: Logged In: YES user_id=140558 I've run the test with the latest SQLObject (no extra patches) and the tests fail too, at least they fail when I run them. As I explained before, there's something wrong when adding columns to sqlite, it fails and all the tests that depend on the added columns fail too. Does it happen to you too? ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-16 16:16 Message: Logged In: YES user_id=4799 These tests fail in both Postgres and SQLite. Two major backends (of 3) for SQLObject. If the problem is in tests you can patch tests, too... test_auto.py: def test_dynamicJoin(self): col = KeyCol('personID', foreignKey='Person') Phone.sqlmeta.addColumn(col, changeSchema=True) join = MultipleJoin('Phone') Person.sqlmeta.addJoin(join) for phone in Phone.select('all'): if phone.phone.startswith('555'): phone.person = Person.selectBy(name='tim')[0] else: phone.person = Person.selectBy(name='bob')[0] > l = [p.phone for p in Person.selectBy(name='tim')[0].phones] [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/test_auto.py:59] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > [failure to get at sourcelines from <TracebackEntry /home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/<string>:1>] [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/<string>:1] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def performJoin(self, inst): ids = inst._connection._SO_selectJoin( self.otherClass, self.joinColumn, > inst.id) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/joins.py:144] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _SO_selectJoin(self, soClass, column, value): return self.queryAll("SELECT %s FROM %s WHERE %s = %s" % (soClass.sqlmeta.idName, soClass.sqlmeta.table, column, > self.sqlrepr(value))) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:652] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def queryAll(self, s): > return self._runWithConnection(self._queryAll, s) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:327] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _runWithConnection(self, meth, *args): conn = self.getConnection() try: > val = meth(conn, *args) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:228] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _queryAll(self, conn, s): if self.debug: self.printDebug(conn, s, 'QueryAll') c = conn.cursor() > self._executeRetry(conn, c, s) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:320] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _executeRetry(self, conn, cursor, query): if self.debug: self.printDebug(conn, query, 'QueryR') E return cursor.execute(query) > OperationalError: no such column: person_id [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:306] - - - - - - - - - - - test_dynamicJoin: recorded stdout - - - - - - - - - - - 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/Query : DELETE FROM person 1/QueryR : DELETE FROM person 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/Query : DELETE FROM phone 1/QueryR : DELETE FROM phone 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('jane') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 1 1/QueryR : SELECT name_col FROM person WHERE id = 1 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('tim') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 2 1/QueryR : SELECT name_col FROM person WHERE id = 2 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('bob') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 3 1/QueryR : SELECT name_col FROM person WHERE id = 3 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('jake') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 4 1/QueryR : SELECT name_col FROM person WHERE id = 4 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('555-555-5555') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 1 1/QueryR : SELECT phone FROM phone WHERE id = 1 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('555-394-2930') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 2 1/QueryR : SELECT phone FROM phone WHERE id = 2 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('444-382-4854') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 3 1/QueryR : SELECT phone FROM phone WHERE id = 3 1/COMMIT : auto 1/Query : ALTER TABLE phone ADD COLUMN person_i_d_id INT 1/QueryR : ALTER TABLE phone ADD COLUMN person_i_d_id INT 1/COMMIT : auto 1/Select : SELECT phone.id, phone.phone, phone.person_i_d_id FROM phone WHERE 1 = 1 ORDER BY phone 1/QueryR : SELECT phone.id, phone.phone, phone.person_i_d_id FROM phone WHERE 1 = 1 ORDER BY phone 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'bob' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'bob' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/QueryAll: SELECT id FROM phone WHERE person_id = 2 1/QueryR : SELECT id FROM phone WHERE person_id = 2 1/COMMIT : auto ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-15 16:54 Message: Logged In: YES user_id=140558 Ok, here I go again. I've fixed a small bug: the name of the field was not porperly set when using Key(foreignKey... instead of ForeignKey. This fixes test_basic. And I think that there is nothing else to fix, I'm probably wrong, but I'll explain it hera. test_auto_old.py... FAIL test_auto.py... FAIL test_foreignKey.py... FAIL These tests fail because sqlite is failing when adding columns. In mysql it does not fail. I do not think it's this patch fault. And finally: test_SQLMultipleJoin.py... FAIL E assert str(hibrid.fightersAsSResult.sum('power')) == '23' > assert '23.0' == '23' + where '23.0' = str(23.0) + where 23.0 = <Race 3 name="'hibrid (human wi...'">.fightersAsSResult.sum('power') Again this is an error in the test. Please let me know if it can go in now :) If you can have a quick look at it better, it takes time to restart ths tests, I'd rather do it before I move on to another thing. Thanks Pau ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-14 10:05 Message: Logged In: YES user_id=140558 Oleg, I've posted to the list because I run the tests and pass. I'm sure I'm doing something wrong but I don't see what. I lost more than 3 hours yesterday just trying to run te tests :( I printed things in dbtest.py and say that TESTDB did not change anything. I chenged manually conftest.py because I ahd a message that yoiu need sqlite2 for memory databases, but still I'm not sure everything works becasue I pass al the tests. Can you help me, I want to close this patch soon and move to other improvements but this is being much more difficult than it should. Thanks a lot Pau ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-09 17:42 Message: Logged In: YES user_id=140558 I'm very busy but again will try to find some time to fix it. I'm using it every day without a glitch, even using the clause attributes like in the Complex example (new type of joins *toMany). I'll update it to latest SVN just in case this is the problem, I did it with that day's current. Please do not close it, I really intend to pass the tests, I'm already using it. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-09 17:11 Message: Logged In: YES user_id=4799 test_auto.py, for example fails: def test_dynamicJoin(self): col = KeyCol('personID', foreignKey='Person') Phone.sqlmeta.addColumn(col, changeSchema=True) join = MultipleJoin('Phone') Person.sqlmeta.addJoin(join) for phone in Phone.select('all'): if phone.phone.startswith('555'): phone.person = Person.selectBy(name='tim')[0] else: phone.person = Person.selectBy(name='bob')[0] l = [p.phone for p in Person.selectBy(name='tim')[0].phones] l.sort() E assert l == ['555-394-2930', '555-555-5555'] > assert [] == ['555-394-2930', '555-555-5555'] [sqlobject/tests/test_auto.py:61] ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-30 19:10 Message: Logged In: YES user_id=140558 I'll recheck it, it really passed all the tests applied to the latest svn. I tell you something tomorrow. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-30 19:07 Message: Logged In: YES user_id=140558 I'll recheck it, it really passed all the tests applied to the latest svn. I tell you something tomorrow. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-30 18:57 Message: Logged In: YES user_id=4799 test_auto.py, test_auto_old.py and test_basic.py failed. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-18 17:04 Message: Logged In: YES user_id=140558 This is the final patch against latest svn, it includes everything in one single patch. It passes the tests. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-18 14:17 Message: Logged In: YES user_id=140558 Ok, I have taken my time to understand pydist, test, etc, and here I am back with the working solution :) Now the resulting SQLobject passes all the tests. I attach an incremental patch so that you can see more clearly the changes done to fix the previous one. I've needed a new method in the Style class, instanceIDAttrToAttr, that is the complementary to the already known instanceAttrToIDAttr. If you need to transform back and forth field names, you need them both. I haven't tried to port it to the latest svn yet, this is against the same release than the first patch, but it should apply more or less clearly as this are very isolated areas in the code. When I do it I'll post it here. Sorry for the delay, it has not been easy for me to understand more deeply the code and, even less, to know how the tests work :) ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-03 13:18 Message: Logged In: YES user_id=140558 It fails because the test is not right, it still has the ID postfix hardcoded. My fault, I did no send a patch for tests. This is the piece that fails: # Select by usual way s = TestWorkKey.selectBy(composerID=c.id, title='Symphony No. 9') I have not looked at tests until now, but it looks like there should be tests for the different provides styles, in this case, if you accept the patch, at least a test for the LongStyle provided and for the current naming styles. I'll try to cook up something, but it can take a little time. Any guidelines will be appreciated (I've just read the docs ;) ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-03 12:23 Message: Logged In: YES user_id=4799 test_selectBy_foreignKey.py fails: def test1(): setupClass([TestComposerKey, TestWorkKey]) c = TestComposerKey(name='Mahler, Gustav') > w1 = TestWorkKey(composer=c, title='Symphony No. 9') [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/tests/test_selectBy_foreignKey.py:19] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def __init__(self, **kw): # The get() classmethod/constructor uses a magic keyword # argument when it wants an empty object, fetched from the # database. So we have nothing more to do in that case: if kw.has_key('_SO_fetch_no_create'): return post_funcs = [] self.sqlmeta.send(events.RowCreateSignal, kw, post_funcs) # Pass the connection object along if we were given one. if kw.has_key('connection'): self._connection = kw['connection'] self.sqlmeta._perConnection = True del kw['connection'] self._SO_writeLock = threading.Lock() if kw.has_key('id'): id = self.sqlmeta.idType(kw['id']) del kw['id'] else: id = None > self._create(id, **kw) [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/main.py:1210] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _create(self, id, **kw): self.sqlmeta._creating = True self._SO_createValues = {} self._SO_validatorState = SQLObjectState(self) # First we do a little fix-up on the keywords we were # passed: for column in self.sqlmeta.columnList: # Then we check if the column wasn't passed in, and # if not we try to get the default. if not kw.has_key(column.name) and not kw.has_key(column.foreignName): default = column.default # If we don't get it, it's an error: if default is NoDefault: E raise TypeError, "%s() did not get expected keyword argument %s" % (self.__class__.__name__, column.name) > TypeError: TestWorkKey() did not get expected keyword argument composerID [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/main.py:1231] - - - - - - - - - - - - - test1: recorded stdout - - - - - - - - - - - - - - 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/Query : CREATE TABLE test_composer_key ( id SERIAL PRIMARY KEY, name TEXT ) 1/QueryR : CREATE TABLE test_composer_key ( id SERIAL PRIMARY KEY, name TEXT ) 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/Query : CREATE TABLE test_work_key ( work_id SERIAL PRIMARY KEY, composer_id INT, title TEXT ) 1/QueryR : CREATE TABLE test_work_key ( work_id SERIAL PRIMARY KEY, composer_id INT, title TEXT ) 1/COMMIT : auto 1/Query : ALTER TABLE test_work_key ADD CONSTRAINT composer_id_exists FOREIGN KEY (composer_id) REFERENCES test_composer_key (id) 1/QueryR : ALTER TABLE test_work_key ADD CONSTRAINT composer_id_exists FOREIGN KEY (composer_id) REFERENCES test_composer_key (id) 1/COMMIT : auto 1/QueryIns: INSERT INTO test_composer_key (id, name) VALUES (1, 'Mahler, Gustav') 1/COMMIT : auto 1/QueryOne: SELECT name FROM test_composer_key WHERE id = 1 1/QueryR : SELECT name FROM test_composer_key WHERE id = 1 1/COMMIT : auto ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1353728&group_id=74338 |
|
From: SourceForge.net <no...@so...> - 2006-02-17 16:07:00
|
Patches item #1353728, was opened at 2005-11-11 10:20 Message generated for change (Comment added) made by phd You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1353728&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open >Resolution: Accepted Priority: 5 Submitted By: Pau Aliagas (linux4u) Assigned to: Oleg Broytmann (phd) Summary: define foreign keys in Style Initial Comment: I don't like to use attrID all along the code to access related tables, I want to be able use the nomeclature I like taking advantage of the nice Style idea. This is especially true when you create RelatedJoins when you use a nomeclature like I do (table.id_table), but it's the same for all the nomeclatures you can imagine. In styles.py it warns: def instanceAttrToIDAttr(self, attr): # @@: Right now, because of how names are created for foreign # keys, you can't really change this style. return attr + "ID" With this patch you can define how you want the foreign keys generated, they won't be mandatorily generated as attrID. Example: class LongStyle(Style): """ This style is derived from Style, that does not do any translation, but constructs the table ids like id_table. """ def instanceAttrToIDAttr(self, attr): return "id_" + attr def tableReference(self, table): # str.rsplit is python 2.4+ only if version_info >= (2, 4): return "id_" + table.rsplit(".", 1)[-1] else: return "id_" + rsplit(table, ".", 1)[-1] class mm_server(SQLObject): class sqlmeta: table = "smsarena.mm_server" style = LongStyle(longID = True) _connection = conn_smsarena server = StringCol(alternateID = True, varchar = True, length = 255, alternateMethodName = "by_server") tz = StringCol(length = 20, default = 'CET', notNone = True) conutry_code = StringCol(length = 2, varchar = False, default = '', notNone = True) # until now I had to do this # mm_server_aliases = SQLMultipleJoin("mm_server_alias", joinColumn = "mm_serverID", orderBy = "server") # now it's perfect! mm_server_aliases = SQLMultipleJoin("mm_server_alias", orderBy = "server") class mm_server_alias(SQLObject): class sqlmeta: table = "smsarena.mm_server_alias" style = LongStyle(longID = True) _connection = conn_smsarena # until now I had to do this # mm_server = ForeignKey("mm_server", dbName = "id_mm_server") mm_server = ForeignKey("mm_server") server = StringCol(alternateID = True, varchar = True, length = 255, alternateMethodName = "by_server") I hope it's clear :) Pau ---------------------------------------------------------------------- >Comment By: Oleg Broytmann (phd) Date: 2006-02-17 19:06 Message: Logged In: YES user_id=4799 SUM() should return whtaver the DB returns. I think summing an INT column returns an int, summing a FLOAT column returns a float. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 18:59 Message: Logged In: YES user_id=140558 Ok, another test mistery solved: This is the culprit that test_SQLMultipleJoin.py fails: assert str(hibrid.fightersAsSResult.sum('power')) == '23' In pgsql hibrid.fightersAsSResult.sum('power') returns 23. In sqlite-3.1.2 and mysql-4.1 it returns 23.0. So we should either fix the test or the sum function. Fixing the test could be as easy as casting the float to int: assert str(int(hibrid.fightersAsSResult.sum('power'))) == '23' but I'mn not sure if this would hide a bug. Should sum return float or int? ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 18:55 Message: Logged In: YES user_id=4799 Yes, it works finally! Applied in the revision 1607. Thank you for the job! How much does it change the API? Does it have meaning to be applied to 0.7 branch? I actually applied it and it passed all tests, but I don't want to break API for 0.7.1. Will all old programs work? ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 18:49 Message: Logged In: YES user_id=140558 After fixing my patch (I'm sure it works now!!) I'm reviewing the tests that fail. See the attached file "failed tests 2006-01-17 version 1" for the tests an the detailed explanations. In summary: test_ForeignKey.py: you know about it, it fails in all the databases test_SQLMultipleJoin.py: I don't see why it fails, it fails in sqlite and mysql, not in pgsql * sqlite * my problem is that sqlite-3.1.2 does not support alter tabble ad column, so no problem. * mysql * test_datetime.py ---------------- to_python does not seem to work as expected. test_enum.py ------------ BLOB/TEXT column indexes require length in mysql I hope that this makes clear the current status. If you accept the current patch, maybe we could open another ticket with the current bugs in mysql and sqlite, as these are clearly separate issues. Thanks ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 16:26 Message: Logged In: YES user_id=140558 I've fixed the problems with addColumns and delColum, now it passes the tests (not the ones that fail I do not why). I've fixed the tests too: I think we should NOT add the columns with ID at the end as the style add it for you. Otherwise I should modify the sytle functions to conditionally check if they end in ID.... I don't think that it is ok, if we want that, we define anthjer style that removes double ID at the end. This is internal to the style and so should be kept. Hope it's ok now :) ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 16:01 Message: Logged In: YES user_id=140558 These are my versions (ignore my comment in the other patch ticket, my misake): mysql-4.1.16-1.FC4.1 postgresql-8.0.7-1.FC4.1 python-psycopg-1.1.21-1.fc4 python-sqlite-1.1.6-1 sqlite-3.1.2-3 ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 15:38 Message: Logged In: YES user_id=4799 Except for the problem i test_ForeignKey.py that I know about... others look pretty strange. Let look at the environment. What DB versions? MySQL, PgSQL, SQLite? Drivers versions? MySQLdb, psycopg, PySQLite? MyPostgres is 7.4, psycopg 1.1.21 and 2.0b5. PySQLite 1.1.7 and 2.1.3. A week ago I upgarded to SQLite 3.3.3 and PySQLite 2.1.3; that eliminated some minor problems with patches I have had with SQLIte 2.8.0 and PySQLite 2.1.0. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 15:11 Message: Logged In: YES user_id=140558 Ok, plain SQLObject from SVN now, no patch. There are tests that fail for me in current SQLObject in mysql, postgres and sqlite. I attach them all. This is a fully updated Fedora 4. I've made the tests in mysql and there are some thet do not pass. I enclose the results and a file where I comment why the fail and a possible solution. The tests that fail in postgres and sqlite are the ones I've already reported (mnore or less). Any help? ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 12:22 Message: Logged In: YES user_id=4799 No, the latest SQLObject passes all tests (how would I commit your other patch if a test fail?) except for minor glitch in test_ForeignKey.py which I'm going to resolve RSN. test_auto.py certainly pass. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 12:13 Message: Logged In: YES user_id=140558 I've run the test with the latest SQLObject (no extra patches) and the tests fail too, at least they fail when I run them. As I explained before, there's something wrong when adding columns to sqlite, it fails and all the tests that depend on the added columns fail too. Does it happen to you too? ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-16 18:16 Message: Logged In: YES user_id=4799 These tests fail in both Postgres and SQLite. Two major backends (of 3) for SQLObject. If the problem is in tests you can patch tests, too... test_auto.py: def test_dynamicJoin(self): col = KeyCol('personID', foreignKey='Person') Phone.sqlmeta.addColumn(col, changeSchema=True) join = MultipleJoin('Phone') Person.sqlmeta.addJoin(join) for phone in Phone.select('all'): if phone.phone.startswith('555'): phone.person = Person.selectBy(name='tim')[0] else: phone.person = Person.selectBy(name='bob')[0] > l = [p.phone for p in Person.selectBy(name='tim')[0].phones] [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/test_auto.py:59] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > [failure to get at sourcelines from <TracebackEntry /home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/<string>:1>] [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/<string>:1] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def performJoin(self, inst): ids = inst._connection._SO_selectJoin( self.otherClass, self.joinColumn, > inst.id) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/joins.py:144] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _SO_selectJoin(self, soClass, column, value): return self.queryAll("SELECT %s FROM %s WHERE %s = %s" % (soClass.sqlmeta.idName, soClass.sqlmeta.table, column, > self.sqlrepr(value))) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:652] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def queryAll(self, s): > return self._runWithConnection(self._queryAll, s) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:327] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _runWithConnection(self, meth, *args): conn = self.getConnection() try: > val = meth(conn, *args) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:228] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _queryAll(self, conn, s): if self.debug: self.printDebug(conn, s, 'QueryAll') c = conn.cursor() > self._executeRetry(conn, c, s) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:320] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _executeRetry(self, conn, cursor, query): if self.debug: self.printDebug(conn, query, 'QueryR') E return cursor.execute(query) > OperationalError: no such column: person_id [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:306] - - - - - - - - - - - test_dynamicJoin: recorded stdout - - - - - - - - - - - 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/Query : DELETE FROM person 1/QueryR : DELETE FROM person 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/Query : DELETE FROM phone 1/QueryR : DELETE FROM phone 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('jane') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 1 1/QueryR : SELECT name_col FROM person WHERE id = 1 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('tim') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 2 1/QueryR : SELECT name_col FROM person WHERE id = 2 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('bob') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 3 1/QueryR : SELECT name_col FROM person WHERE id = 3 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('jake') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 4 1/QueryR : SELECT name_col FROM person WHERE id = 4 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('555-555-5555') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 1 1/QueryR : SELECT phone FROM phone WHERE id = 1 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('555-394-2930') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 2 1/QueryR : SELECT phone FROM phone WHERE id = 2 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('444-382-4854') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 3 1/QueryR : SELECT phone FROM phone WHERE id = 3 1/COMMIT : auto 1/Query : ALTER TABLE phone ADD COLUMN person_i_d_id INT 1/QueryR : ALTER TABLE phone ADD COLUMN person_i_d_id INT 1/COMMIT : auto 1/Select : SELECT phone.id, phone.phone, phone.person_i_d_id FROM phone WHERE 1 = 1 ORDER BY phone 1/QueryR : SELECT phone.id, phone.phone, phone.person_i_d_id FROM phone WHERE 1 = 1 ORDER BY phone 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'bob' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'bob' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/QueryAll: SELECT id FROM phone WHERE person_id = 2 1/QueryR : SELECT id FROM phone WHERE person_id = 2 1/COMMIT : auto ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-15 18:54 Message: Logged In: YES user_id=140558 Ok, here I go again. I've fixed a small bug: the name of the field was not porperly set when using Key(foreignKey... instead of ForeignKey. This fixes test_basic. And I think that there is nothing else to fix, I'm probably wrong, but I'll explain it hera. test_auto_old.py... FAIL test_auto.py... FAIL test_foreignKey.py... FAIL These tests fail because sqlite is failing when adding columns. In mysql it does not fail. I do not think it's this patch fault. And finally: test_SQLMultipleJoin.py... FAIL E assert str(hibrid.fightersAsSResult.sum('power')) == '23' > assert '23.0' == '23' + where '23.0' = str(23.0) + where 23.0 = <Race 3 name="'hibrid (human wi...'">.fightersAsSResult.sum('power') Again this is an error in the test. Please let me know if it can go in now :) If you can have a quick look at it better, it takes time to restart ths tests, I'd rather do it before I move on to another thing. Thanks Pau ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-14 12:05 Message: Logged In: YES user_id=140558 Oleg, I've posted to the list because I run the tests and pass. I'm sure I'm doing something wrong but I don't see what. I lost more than 3 hours yesterday just trying to run te tests :( I printed things in dbtest.py and say that TESTDB did not change anything. I chenged manually conftest.py because I ahd a message that yoiu need sqlite2 for memory databases, but still I'm not sure everything works becasue I pass al the tests. Can you help me, I want to close this patch soon and move to other improvements but this is being much more difficult than it should. Thanks a lot Pau ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-09 19:42 Message: Logged In: YES user_id=140558 I'm very busy but again will try to find some time to fix it. I'm using it every day without a glitch, even using the clause attributes like in the Complex example (new type of joins *toMany). I'll update it to latest SVN just in case this is the problem, I did it with that day's current. Please do not close it, I really intend to pass the tests, I'm already using it. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-09 19:11 Message: Logged In: YES user_id=4799 test_auto.py, for example fails: def test_dynamicJoin(self): col = KeyCol('personID', foreignKey='Person') Phone.sqlmeta.addColumn(col, changeSchema=True) join = MultipleJoin('Phone') Person.sqlmeta.addJoin(join) for phone in Phone.select('all'): if phone.phone.startswith('555'): phone.person = Person.selectBy(name='tim')[0] else: phone.person = Person.selectBy(name='bob')[0] l = [p.phone for p in Person.selectBy(name='tim')[0].phones] l.sort() E assert l == ['555-394-2930', '555-555-5555'] > assert [] == ['555-394-2930', '555-555-5555'] [sqlobject/tests/test_auto.py:61] ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-30 21:10 Message: Logged In: YES user_id=140558 I'll recheck it, it really passed all the tests applied to the latest svn. I tell you something tomorrow. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-30 21:07 Message: Logged In: YES user_id=140558 I'll recheck it, it really passed all the tests applied to the latest svn. I tell you something tomorrow. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-30 20:57 Message: Logged In: YES user_id=4799 test_auto.py, test_auto_old.py and test_basic.py failed. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-18 19:04 Message: Logged In: YES user_id=140558 This is the final patch against latest svn, it includes everything in one single patch. It passes the tests. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-18 16:17 Message: Logged In: YES user_id=140558 Ok, I have taken my time to understand pydist, test, etc, and here I am back with the working solution :) Now the resulting SQLobject passes all the tests. I attach an incremental patch so that you can see more clearly the changes done to fix the previous one. I've needed a new method in the Style class, instanceIDAttrToAttr, that is the complementary to the already known instanceAttrToIDAttr. If you need to transform back and forth field names, you need them both. I haven't tried to port it to the latest svn yet, this is against the same release than the first patch, but it should apply more or less clearly as this are very isolated areas in the code. When I do it I'll post it here. Sorry for the delay, it has not been easy for me to understand more deeply the code and, even less, to know how the tests work :) ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-03 15:18 Message: Logged In: YES user_id=140558 It fails because the test is not right, it still has the ID postfix hardcoded. My fault, I did no send a patch for tests. This is the piece that fails: # Select by usual way s = TestWorkKey.selectBy(composerID=c.id, title='Symphony No. 9') I have not looked at tests until now, but it looks like there should be tests for the different provides styles, in this case, if you accept the patch, at least a test for the LongStyle provided and for the current naming styles. I'll try to cook up something, but it can take a little time. Any guidelines will be appreciated (I've just read the docs ;) ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-03 14:23 Message: Logged In: YES user_id=4799 test_selectBy_foreignKey.py fails: def test1(): setupClass([TestComposerKey, TestWorkKey]) c = TestComposerKey(name='Mahler, Gustav') > w1 = TestWorkKey(composer=c, title='Symphony No. 9') [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/tests/test_selectBy_foreignKey.py:19] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def __init__(self, **kw): # The get() classmethod/constructor uses a magic keyword # argument when it wants an empty object, fetched from the # database. So we have nothing more to do in that case: if kw.has_key('_SO_fetch_no_create'): return post_funcs = [] self.sqlmeta.send(events.RowCreateSignal, kw, post_funcs) # Pass the connection object along if we were given one. if kw.has_key('connection'): self._connection = kw['connection'] self.sqlmeta._perConnection = True del kw['connection'] self._SO_writeLock = threading.Lock() if kw.has_key('id'): id = self.sqlmeta.idType(kw['id']) del kw['id'] else: id = None > self._create(id, **kw) [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/main.py:1210] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _create(self, id, **kw): self.sqlmeta._creating = True self._SO_createValues = {} self._SO_validatorState = SQLObjectState(self) # First we do a little fix-up on the keywords we were # passed: for column in self.sqlmeta.columnList: # Then we check if the column wasn't passed in, and # if not we try to get the default. if not kw.has_key(column.name) and not kw.has_key(column.foreignName): default = column.default # If we don't get it, it's an error: if default is NoDefault: E raise TypeError, "%s() did not get expected keyword argument %s" % (self.__class__.__name__, column.name) > TypeError: TestWorkKey() did not get expected keyword argument composerID [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/main.py:1231] - - - - - - - - - - - - - test1: recorded stdout - - - - - - - - - - - - - - 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/Query : CREATE TABLE test_composer_key ( id SERIAL PRIMARY KEY, name TEXT ) 1/QueryR : CREATE TABLE test_composer_key ( id SERIAL PRIMARY KEY, name TEXT ) 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/Query : CREATE TABLE test_work_key ( work_id SERIAL PRIMARY KEY, composer_id INT, title TEXT ) 1/QueryR : CREATE TABLE test_work_key ( work_id SERIAL PRIMARY KEY, composer_id INT, title TEXT ) 1/COMMIT : auto 1/Query : ALTER TABLE test_work_key ADD CONSTRAINT composer_id_exists FOREIGN KEY (composer_id) REFERENCES test_composer_key (id) 1/QueryR : ALTER TABLE test_work_key ADD CONSTRAINT composer_id_exists FOREIGN KEY (composer_id) REFERENCES test_composer_key (id) 1/COMMIT : auto 1/QueryIns: INSERT INTO test_composer_key (id, name) VALUES (1, 'Mahler, Gustav') 1/COMMIT : auto 1/QueryOne: SELECT name FROM test_composer_key WHERE id = 1 1/QueryR : SELECT name FROM test_composer_key WHERE id = 1 1/COMMIT : auto ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1353728&group_id=74338 |
|
From: SourceForge.net <no...@so...> - 2006-02-17 15:59:51
|
Patches item #1353728, was opened at 2005-11-11 08:20 Message generated for change (Comment added) made by linux4u You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1353728&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open >Resolution: Invalid Priority: 5 Submitted By: Pau Aliagas (linux4u) Assigned to: Oleg Broytmann (phd) Summary: define foreign keys in Style Initial Comment: I don't like to use attrID all along the code to access related tables, I want to be able use the nomeclature I like taking advantage of the nice Style idea. This is especially true when you create RelatedJoins when you use a nomeclature like I do (table.id_table), but it's the same for all the nomeclatures you can imagine. In styles.py it warns: def instanceAttrToIDAttr(self, attr): # @@: Right now, because of how names are created for foreign # keys, you can't really change this style. return attr + "ID" With this patch you can define how you want the foreign keys generated, they won't be mandatorily generated as attrID. Example: class LongStyle(Style): """ This style is derived from Style, that does not do any translation, but constructs the table ids like id_table. """ def instanceAttrToIDAttr(self, attr): return "id_" + attr def tableReference(self, table): # str.rsplit is python 2.4+ only if version_info >= (2, 4): return "id_" + table.rsplit(".", 1)[-1] else: return "id_" + rsplit(table, ".", 1)[-1] class mm_server(SQLObject): class sqlmeta: table = "smsarena.mm_server" style = LongStyle(longID = True) _connection = conn_smsarena server = StringCol(alternateID = True, varchar = True, length = 255, alternateMethodName = "by_server") tz = StringCol(length = 20, default = 'CET', notNone = True) conutry_code = StringCol(length = 2, varchar = False, default = '', notNone = True) # until now I had to do this # mm_server_aliases = SQLMultipleJoin("mm_server_alias", joinColumn = "mm_serverID", orderBy = "server") # now it's perfect! mm_server_aliases = SQLMultipleJoin("mm_server_alias", orderBy = "server") class mm_server_alias(SQLObject): class sqlmeta: table = "smsarena.mm_server_alias" style = LongStyle(longID = True) _connection = conn_smsarena # until now I had to do this # mm_server = ForeignKey("mm_server", dbName = "id_mm_server") mm_server = ForeignKey("mm_server") server = StringCol(alternateID = True, varchar = True, length = 255, alternateMethodName = "by_server") I hope it's clear :) Pau ---------------------------------------------------------------------- >Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 16:59 Message: Logged In: YES user_id=140558 Ok, another test mistery solved: This is the culprit that test_SQLMultipleJoin.py fails: assert str(hibrid.fightersAsSResult.sum('power')) == '23' In pgsql hibrid.fightersAsSResult.sum('power') returns 23. In sqlite-3.1.2 and mysql-4.1 it returns 23.0. So we should either fix the test or the sum function. Fixing the test could be as easy as casting the float to int: assert str(int(hibrid.fightersAsSResult.sum('power'))) == '23' but I'mn not sure if this would hide a bug. Should sum return float or int? ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 16:55 Message: Logged In: YES user_id=4799 Yes, it works finally! Applied in the revision 1607. Thank you for the job! How much does it change the API? Does it have meaning to be applied to 0.7 branch? I actually applied it and it passed all tests, but I don't want to break API for 0.7.1. Will all old programs work? ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 16:49 Message: Logged In: YES user_id=140558 After fixing my patch (I'm sure it works now!!) I'm reviewing the tests that fail. See the attached file "failed tests 2006-01-17 version 1" for the tests an the detailed explanations. In summary: test_ForeignKey.py: you know about it, it fails in all the databases test_SQLMultipleJoin.py: I don't see why it fails, it fails in sqlite and mysql, not in pgsql * sqlite * my problem is that sqlite-3.1.2 does not support alter tabble ad column, so no problem. * mysql * test_datetime.py ---------------- to_python does not seem to work as expected. test_enum.py ------------ BLOB/TEXT column indexes require length in mysql I hope that this makes clear the current status. If you accept the current patch, maybe we could open another ticket with the current bugs in mysql and sqlite, as these are clearly separate issues. Thanks ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 14:26 Message: Logged In: YES user_id=140558 I've fixed the problems with addColumns and delColum, now it passes the tests (not the ones that fail I do not why). I've fixed the tests too: I think we should NOT add the columns with ID at the end as the style add it for you. Otherwise I should modify the sytle functions to conditionally check if they end in ID.... I don't think that it is ok, if we want that, we define anthjer style that removes double ID at the end. This is internal to the style and so should be kept. Hope it's ok now :) ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 14:01 Message: Logged In: YES user_id=140558 These are my versions (ignore my comment in the other patch ticket, my misake): mysql-4.1.16-1.FC4.1 postgresql-8.0.7-1.FC4.1 python-psycopg-1.1.21-1.fc4 python-sqlite-1.1.6-1 sqlite-3.1.2-3 ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 13:38 Message: Logged In: YES user_id=4799 Except for the problem i test_ForeignKey.py that I know about... others look pretty strange. Let look at the environment. What DB versions? MySQL, PgSQL, SQLite? Drivers versions? MySQLdb, psycopg, PySQLite? MyPostgres is 7.4, psycopg 1.1.21 and 2.0b5. PySQLite 1.1.7 and 2.1.3. A week ago I upgarded to SQLite 3.3.3 and PySQLite 2.1.3; that eliminated some minor problems with patches I have had with SQLIte 2.8.0 and PySQLite 2.1.0. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 13:11 Message: Logged In: YES user_id=140558 Ok, plain SQLObject from SVN now, no patch. There are tests that fail for me in current SQLObject in mysql, postgres and sqlite. I attach them all. This is a fully updated Fedora 4. I've made the tests in mysql and there are some thet do not pass. I enclose the results and a file where I comment why the fail and a possible solution. The tests that fail in postgres and sqlite are the ones I've already reported (mnore or less). Any help? ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 10:22 Message: Logged In: YES user_id=4799 No, the latest SQLObject passes all tests (how would I commit your other patch if a test fail?) except for minor glitch in test_ForeignKey.py which I'm going to resolve RSN. test_auto.py certainly pass. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 10:13 Message: Logged In: YES user_id=140558 I've run the test with the latest SQLObject (no extra patches) and the tests fail too, at least they fail when I run them. As I explained before, there's something wrong when adding columns to sqlite, it fails and all the tests that depend on the added columns fail too. Does it happen to you too? ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-16 16:16 Message: Logged In: YES user_id=4799 These tests fail in both Postgres and SQLite. Two major backends (of 3) for SQLObject. If the problem is in tests you can patch tests, too... test_auto.py: def test_dynamicJoin(self): col = KeyCol('personID', foreignKey='Person') Phone.sqlmeta.addColumn(col, changeSchema=True) join = MultipleJoin('Phone') Person.sqlmeta.addJoin(join) for phone in Phone.select('all'): if phone.phone.startswith('555'): phone.person = Person.selectBy(name='tim')[0] else: phone.person = Person.selectBy(name='bob')[0] > l = [p.phone for p in Person.selectBy(name='tim')[0].phones] [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/test_auto.py:59] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > [failure to get at sourcelines from <TracebackEntry /home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/<string>:1>] [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/<string>:1] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def performJoin(self, inst): ids = inst._connection._SO_selectJoin( self.otherClass, self.joinColumn, > inst.id) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/joins.py:144] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _SO_selectJoin(self, soClass, column, value): return self.queryAll("SELECT %s FROM %s WHERE %s = %s" % (soClass.sqlmeta.idName, soClass.sqlmeta.table, column, > self.sqlrepr(value))) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:652] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def queryAll(self, s): > return self._runWithConnection(self._queryAll, s) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:327] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _runWithConnection(self, meth, *args): conn = self.getConnection() try: > val = meth(conn, *args) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:228] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _queryAll(self, conn, s): if self.debug: self.printDebug(conn, s, 'QueryAll') c = conn.cursor() > self._executeRetry(conn, c, s) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:320] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _executeRetry(self, conn, cursor, query): if self.debug: self.printDebug(conn, query, 'QueryR') E return cursor.execute(query) > OperationalError: no such column: person_id [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:306] - - - - - - - - - - - test_dynamicJoin: recorded stdout - - - - - - - - - - - 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/Query : DELETE FROM person 1/QueryR : DELETE FROM person 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/Query : DELETE FROM phone 1/QueryR : DELETE FROM phone 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('jane') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 1 1/QueryR : SELECT name_col FROM person WHERE id = 1 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('tim') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 2 1/QueryR : SELECT name_col FROM person WHERE id = 2 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('bob') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 3 1/QueryR : SELECT name_col FROM person WHERE id = 3 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('jake') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 4 1/QueryR : SELECT name_col FROM person WHERE id = 4 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('555-555-5555') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 1 1/QueryR : SELECT phone FROM phone WHERE id = 1 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('555-394-2930') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 2 1/QueryR : SELECT phone FROM phone WHERE id = 2 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('444-382-4854') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 3 1/QueryR : SELECT phone FROM phone WHERE id = 3 1/COMMIT : auto 1/Query : ALTER TABLE phone ADD COLUMN person_i_d_id INT 1/QueryR : ALTER TABLE phone ADD COLUMN person_i_d_id INT 1/COMMIT : auto 1/Select : SELECT phone.id, phone.phone, phone.person_i_d_id FROM phone WHERE 1 = 1 ORDER BY phone 1/QueryR : SELECT phone.id, phone.phone, phone.person_i_d_id FROM phone WHERE 1 = 1 ORDER BY phone 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'bob' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'bob' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/QueryAll: SELECT id FROM phone WHERE person_id = 2 1/QueryR : SELECT id FROM phone WHERE person_id = 2 1/COMMIT : auto ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-15 16:54 Message: Logged In: YES user_id=140558 Ok, here I go again. I've fixed a small bug: the name of the field was not porperly set when using Key(foreignKey... instead of ForeignKey. This fixes test_basic. And I think that there is nothing else to fix, I'm probably wrong, but I'll explain it hera. test_auto_old.py... FAIL test_auto.py... FAIL test_foreignKey.py... FAIL These tests fail because sqlite is failing when adding columns. In mysql it does not fail. I do not think it's this patch fault. And finally: test_SQLMultipleJoin.py... FAIL E assert str(hibrid.fightersAsSResult.sum('power')) == '23' > assert '23.0' == '23' + where '23.0' = str(23.0) + where 23.0 = <Race 3 name="'hibrid (human wi...'">.fightersAsSResult.sum('power') Again this is an error in the test. Please let me know if it can go in now :) If you can have a quick look at it better, it takes time to restart ths tests, I'd rather do it before I move on to another thing. Thanks Pau ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-14 10:05 Message: Logged In: YES user_id=140558 Oleg, I've posted to the list because I run the tests and pass. I'm sure I'm doing something wrong but I don't see what. I lost more than 3 hours yesterday just trying to run te tests :( I printed things in dbtest.py and say that TESTDB did not change anything. I chenged manually conftest.py because I ahd a message that yoiu need sqlite2 for memory databases, but still I'm not sure everything works becasue I pass al the tests. Can you help me, I want to close this patch soon and move to other improvements but this is being much more difficult than it should. Thanks a lot Pau ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-09 17:42 Message: Logged In: YES user_id=140558 I'm very busy but again will try to find some time to fix it. I'm using it every day without a glitch, even using the clause attributes like in the Complex example (new type of joins *toMany). I'll update it to latest SVN just in case this is the problem, I did it with that day's current. Please do not close it, I really intend to pass the tests, I'm already using it. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-09 17:11 Message: Logged In: YES user_id=4799 test_auto.py, for example fails: def test_dynamicJoin(self): col = KeyCol('personID', foreignKey='Person') Phone.sqlmeta.addColumn(col, changeSchema=True) join = MultipleJoin('Phone') Person.sqlmeta.addJoin(join) for phone in Phone.select('all'): if phone.phone.startswith('555'): phone.person = Person.selectBy(name='tim')[0] else: phone.person = Person.selectBy(name='bob')[0] l = [p.phone for p in Person.selectBy(name='tim')[0].phones] l.sort() E assert l == ['555-394-2930', '555-555-5555'] > assert [] == ['555-394-2930', '555-555-5555'] [sqlobject/tests/test_auto.py:61] ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-30 19:10 Message: Logged In: YES user_id=140558 I'll recheck it, it really passed all the tests applied to the latest svn. I tell you something tomorrow. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-30 19:07 Message: Logged In: YES user_id=140558 I'll recheck it, it really passed all the tests applied to the latest svn. I tell you something tomorrow. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-30 18:57 Message: Logged In: YES user_id=4799 test_auto.py, test_auto_old.py and test_basic.py failed. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-18 17:04 Message: Logged In: YES user_id=140558 This is the final patch against latest svn, it includes everything in one single patch. It passes the tests. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-18 14:17 Message: Logged In: YES user_id=140558 Ok, I have taken my time to understand pydist, test, etc, and here I am back with the working solution :) Now the resulting SQLobject passes all the tests. I attach an incremental patch so that you can see more clearly the changes done to fix the previous one. I've needed a new method in the Style class, instanceIDAttrToAttr, that is the complementary to the already known instanceAttrToIDAttr. If you need to transform back and forth field names, you need them both. I haven't tried to port it to the latest svn yet, this is against the same release than the first patch, but it should apply more or less clearly as this are very isolated areas in the code. When I do it I'll post it here. Sorry for the delay, it has not been easy for me to understand more deeply the code and, even less, to know how the tests work :) ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-03 13:18 Message: Logged In: YES user_id=140558 It fails because the test is not right, it still has the ID postfix hardcoded. My fault, I did no send a patch for tests. This is the piece that fails: # Select by usual way s = TestWorkKey.selectBy(composerID=c.id, title='Symphony No. 9') I have not looked at tests until now, but it looks like there should be tests for the different provides styles, in this case, if you accept the patch, at least a test for the LongStyle provided and for the current naming styles. I'll try to cook up something, but it can take a little time. Any guidelines will be appreciated (I've just read the docs ;) ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-03 12:23 Message: Logged In: YES user_id=4799 test_selectBy_foreignKey.py fails: def test1(): setupClass([TestComposerKey, TestWorkKey]) c = TestComposerKey(name='Mahler, Gustav') > w1 = TestWorkKey(composer=c, title='Symphony No. 9') [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/tests/test_selectBy_foreignKey.py:19] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def __init__(self, **kw): # The get() classmethod/constructor uses a magic keyword # argument when it wants an empty object, fetched from the # database. So we have nothing more to do in that case: if kw.has_key('_SO_fetch_no_create'): return post_funcs = [] self.sqlmeta.send(events.RowCreateSignal, kw, post_funcs) # Pass the connection object along if we were given one. if kw.has_key('connection'): self._connection = kw['connection'] self.sqlmeta._perConnection = True del kw['connection'] self._SO_writeLock = threading.Lock() if kw.has_key('id'): id = self.sqlmeta.idType(kw['id']) del kw['id'] else: id = None > self._create(id, **kw) [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/main.py:1210] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _create(self, id, **kw): self.sqlmeta._creating = True self._SO_createValues = {} self._SO_validatorState = SQLObjectState(self) # First we do a little fix-up on the keywords we were # passed: for column in self.sqlmeta.columnList: # Then we check if the column wasn't passed in, and # if not we try to get the default. if not kw.has_key(column.name) and not kw.has_key(column.foreignName): default = column.default # If we don't get it, it's an error: if default is NoDefault: E raise TypeError, "%s() did not get expected keyword argument %s" % (self.__class__.__name__, column.name) > TypeError: TestWorkKey() did not get expected keyword argument composerID [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/main.py:1231] - - - - - - - - - - - - - test1: recorded stdout - - - - - - - - - - - - - - 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/Query : CREATE TABLE test_composer_key ( id SERIAL PRIMARY KEY, name TEXT ) 1/QueryR : CREATE TABLE test_composer_key ( id SERIAL PRIMARY KEY, name TEXT ) 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/Query : CREATE TABLE test_work_key ( work_id SERIAL PRIMARY KEY, composer_id INT, title TEXT ) 1/QueryR : CREATE TABLE test_work_key ( work_id SERIAL PRIMARY KEY, composer_id INT, title TEXT ) 1/COMMIT : auto 1/Query : ALTER TABLE test_work_key ADD CONSTRAINT composer_id_exists FOREIGN KEY (composer_id) REFERENCES test_composer_key (id) 1/QueryR : ALTER TABLE test_work_key ADD CONSTRAINT composer_id_exists FOREIGN KEY (composer_id) REFERENCES test_composer_key (id) 1/COMMIT : auto 1/QueryIns: INSERT INTO test_composer_key (id, name) VALUES (1, 'Mahler, Gustav') 1/COMMIT : auto 1/QueryOne: SELECT name FROM test_composer_key WHERE id = 1 1/QueryR : SELECT name FROM test_composer_key WHERE id = 1 1/COMMIT : auto ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1353728&group_id=74338 |
|
From: SourceForge.net <no...@so...> - 2006-02-17 15:55:24
|
Patches item #1353728, was opened at 2005-11-11 10:20 Message generated for change (Comment added) made by phd You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1353728&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open >Resolution: Accepted Priority: 5 Submitted By: Pau Aliagas (linux4u) Assigned to: Oleg Broytmann (phd) Summary: define foreign keys in Style Initial Comment: I don't like to use attrID all along the code to access related tables, I want to be able use the nomeclature I like taking advantage of the nice Style idea. This is especially true when you create RelatedJoins when you use a nomeclature like I do (table.id_table), but it's the same for all the nomeclatures you can imagine. In styles.py it warns: def instanceAttrToIDAttr(self, attr): # @@: Right now, because of how names are created for foreign # keys, you can't really change this style. return attr + "ID" With this patch you can define how you want the foreign keys generated, they won't be mandatorily generated as attrID. Example: class LongStyle(Style): """ This style is derived from Style, that does not do any translation, but constructs the table ids like id_table. """ def instanceAttrToIDAttr(self, attr): return "id_" + attr def tableReference(self, table): # str.rsplit is python 2.4+ only if version_info >= (2, 4): return "id_" + table.rsplit(".", 1)[-1] else: return "id_" + rsplit(table, ".", 1)[-1] class mm_server(SQLObject): class sqlmeta: table = "smsarena.mm_server" style = LongStyle(longID = True) _connection = conn_smsarena server = StringCol(alternateID = True, varchar = True, length = 255, alternateMethodName = "by_server") tz = StringCol(length = 20, default = 'CET', notNone = True) conutry_code = StringCol(length = 2, varchar = False, default = '', notNone = True) # until now I had to do this # mm_server_aliases = SQLMultipleJoin("mm_server_alias", joinColumn = "mm_serverID", orderBy = "server") # now it's perfect! mm_server_aliases = SQLMultipleJoin("mm_server_alias", orderBy = "server") class mm_server_alias(SQLObject): class sqlmeta: table = "smsarena.mm_server_alias" style = LongStyle(longID = True) _connection = conn_smsarena # until now I had to do this # mm_server = ForeignKey("mm_server", dbName = "id_mm_server") mm_server = ForeignKey("mm_server") server = StringCol(alternateID = True, varchar = True, length = 255, alternateMethodName = "by_server") I hope it's clear :) Pau ---------------------------------------------------------------------- >Comment By: Oleg Broytmann (phd) Date: 2006-02-17 18:55 Message: Logged In: YES user_id=4799 Yes, it works finally! Applied in the revision 1607. Thank you for the job! How much does it change the API? Does it have meaning to be applied to 0.7 branch? I actually applied it and it passed all tests, but I don't want to break API for 0.7.1. Will all old programs work? ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 18:49 Message: Logged In: YES user_id=140558 After fixing my patch (I'm sure it works now!!) I'm reviewing the tests that fail. See the attached file "failed tests 2006-01-17 version 1" for the tests an the detailed explanations. In summary: test_ForeignKey.py: you know about it, it fails in all the databases test_SQLMultipleJoin.py: I don't see why it fails, it fails in sqlite and mysql, not in pgsql * sqlite * my problem is that sqlite-3.1.2 does not support alter tabble ad column, so no problem. * mysql * test_datetime.py ---------------- to_python does not seem to work as expected. test_enum.py ------------ BLOB/TEXT column indexes require length in mysql I hope that this makes clear the current status. If you accept the current patch, maybe we could open another ticket with the current bugs in mysql and sqlite, as these are clearly separate issues. Thanks ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 16:26 Message: Logged In: YES user_id=140558 I've fixed the problems with addColumns and delColum, now it passes the tests (not the ones that fail I do not why). I've fixed the tests too: I think we should NOT add the columns with ID at the end as the style add it for you. Otherwise I should modify the sytle functions to conditionally check if they end in ID.... I don't think that it is ok, if we want that, we define anthjer style that removes double ID at the end. This is internal to the style and so should be kept. Hope it's ok now :) ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 16:01 Message: Logged In: YES user_id=140558 These are my versions (ignore my comment in the other patch ticket, my misake): mysql-4.1.16-1.FC4.1 postgresql-8.0.7-1.FC4.1 python-psycopg-1.1.21-1.fc4 python-sqlite-1.1.6-1 sqlite-3.1.2-3 ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 15:38 Message: Logged In: YES user_id=4799 Except for the problem i test_ForeignKey.py that I know about... others look pretty strange. Let look at the environment. What DB versions? MySQL, PgSQL, SQLite? Drivers versions? MySQLdb, psycopg, PySQLite? MyPostgres is 7.4, psycopg 1.1.21 and 2.0b5. PySQLite 1.1.7 and 2.1.3. A week ago I upgarded to SQLite 3.3.3 and PySQLite 2.1.3; that eliminated some minor problems with patches I have had with SQLIte 2.8.0 and PySQLite 2.1.0. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 15:11 Message: Logged In: YES user_id=140558 Ok, plain SQLObject from SVN now, no patch. There are tests that fail for me in current SQLObject in mysql, postgres and sqlite. I attach them all. This is a fully updated Fedora 4. I've made the tests in mysql and there are some thet do not pass. I enclose the results and a file where I comment why the fail and a possible solution. The tests that fail in postgres and sqlite are the ones I've already reported (mnore or less). Any help? ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 12:22 Message: Logged In: YES user_id=4799 No, the latest SQLObject passes all tests (how would I commit your other patch if a test fail?) except for minor glitch in test_ForeignKey.py which I'm going to resolve RSN. test_auto.py certainly pass. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 12:13 Message: Logged In: YES user_id=140558 I've run the test with the latest SQLObject (no extra patches) and the tests fail too, at least they fail when I run them. As I explained before, there's something wrong when adding columns to sqlite, it fails and all the tests that depend on the added columns fail too. Does it happen to you too? ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-16 18:16 Message: Logged In: YES user_id=4799 These tests fail in both Postgres and SQLite. Two major backends (of 3) for SQLObject. If the problem is in tests you can patch tests, too... test_auto.py: def test_dynamicJoin(self): col = KeyCol('personID', foreignKey='Person') Phone.sqlmeta.addColumn(col, changeSchema=True) join = MultipleJoin('Phone') Person.sqlmeta.addJoin(join) for phone in Phone.select('all'): if phone.phone.startswith('555'): phone.person = Person.selectBy(name='tim')[0] else: phone.person = Person.selectBy(name='bob')[0] > l = [p.phone for p in Person.selectBy(name='tim')[0].phones] [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/test_auto.py:59] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > [failure to get at sourcelines from <TracebackEntry /home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/<string>:1>] [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/<string>:1] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def performJoin(self, inst): ids = inst._connection._SO_selectJoin( self.otherClass, self.joinColumn, > inst.id) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/joins.py:144] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _SO_selectJoin(self, soClass, column, value): return self.queryAll("SELECT %s FROM %s WHERE %s = %s" % (soClass.sqlmeta.idName, soClass.sqlmeta.table, column, > self.sqlrepr(value))) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:652] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def queryAll(self, s): > return self._runWithConnection(self._queryAll, s) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:327] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _runWithConnection(self, meth, *args): conn = self.getConnection() try: > val = meth(conn, *args) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:228] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _queryAll(self, conn, s): if self.debug: self.printDebug(conn, s, 'QueryAll') c = conn.cursor() > self._executeRetry(conn, c, s) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:320] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _executeRetry(self, conn, cursor, query): if self.debug: self.printDebug(conn, query, 'QueryR') E return cursor.execute(query) > OperationalError: no such column: person_id [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:306] - - - - - - - - - - - test_dynamicJoin: recorded stdout - - - - - - - - - - - 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/Query : DELETE FROM person 1/QueryR : DELETE FROM person 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/Query : DELETE FROM phone 1/QueryR : DELETE FROM phone 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('jane') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 1 1/QueryR : SELECT name_col FROM person WHERE id = 1 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('tim') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 2 1/QueryR : SELECT name_col FROM person WHERE id = 2 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('bob') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 3 1/QueryR : SELECT name_col FROM person WHERE id = 3 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('jake') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 4 1/QueryR : SELECT name_col FROM person WHERE id = 4 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('555-555-5555') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 1 1/QueryR : SELECT phone FROM phone WHERE id = 1 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('555-394-2930') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 2 1/QueryR : SELECT phone FROM phone WHERE id = 2 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('444-382-4854') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 3 1/QueryR : SELECT phone FROM phone WHERE id = 3 1/COMMIT : auto 1/Query : ALTER TABLE phone ADD COLUMN person_i_d_id INT 1/QueryR : ALTER TABLE phone ADD COLUMN person_i_d_id INT 1/COMMIT : auto 1/Select : SELECT phone.id, phone.phone, phone.person_i_d_id FROM phone WHERE 1 = 1 ORDER BY phone 1/QueryR : SELECT phone.id, phone.phone, phone.person_i_d_id FROM phone WHERE 1 = 1 ORDER BY phone 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'bob' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'bob' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/QueryAll: SELECT id FROM phone WHERE person_id = 2 1/QueryR : SELECT id FROM phone WHERE person_id = 2 1/COMMIT : auto ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-15 18:54 Message: Logged In: YES user_id=140558 Ok, here I go again. I've fixed a small bug: the name of the field was not porperly set when using Key(foreignKey... instead of ForeignKey. This fixes test_basic. And I think that there is nothing else to fix, I'm probably wrong, but I'll explain it hera. test_auto_old.py... FAIL test_auto.py... FAIL test_foreignKey.py... FAIL These tests fail because sqlite is failing when adding columns. In mysql it does not fail. I do not think it's this patch fault. And finally: test_SQLMultipleJoin.py... FAIL E assert str(hibrid.fightersAsSResult.sum('power')) == '23' > assert '23.0' == '23' + where '23.0' = str(23.0) + where 23.0 = <Race 3 name="'hibrid (human wi...'">.fightersAsSResult.sum('power') Again this is an error in the test. Please let me know if it can go in now :) If you can have a quick look at it better, it takes time to restart ths tests, I'd rather do it before I move on to another thing. Thanks Pau ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-14 12:05 Message: Logged In: YES user_id=140558 Oleg, I've posted to the list because I run the tests and pass. I'm sure I'm doing something wrong but I don't see what. I lost more than 3 hours yesterday just trying to run te tests :( I printed things in dbtest.py and say that TESTDB did not change anything. I chenged manually conftest.py because I ahd a message that yoiu need sqlite2 for memory databases, but still I'm not sure everything works becasue I pass al the tests. Can you help me, I want to close this patch soon and move to other improvements but this is being much more difficult than it should. Thanks a lot Pau ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-09 19:42 Message: Logged In: YES user_id=140558 I'm very busy but again will try to find some time to fix it. I'm using it every day without a glitch, even using the clause attributes like in the Complex example (new type of joins *toMany). I'll update it to latest SVN just in case this is the problem, I did it with that day's current. Please do not close it, I really intend to pass the tests, I'm already using it. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-09 19:11 Message: Logged In: YES user_id=4799 test_auto.py, for example fails: def test_dynamicJoin(self): col = KeyCol('personID', foreignKey='Person') Phone.sqlmeta.addColumn(col, changeSchema=True) join = MultipleJoin('Phone') Person.sqlmeta.addJoin(join) for phone in Phone.select('all'): if phone.phone.startswith('555'): phone.person = Person.selectBy(name='tim')[0] else: phone.person = Person.selectBy(name='bob')[0] l = [p.phone for p in Person.selectBy(name='tim')[0].phones] l.sort() E assert l == ['555-394-2930', '555-555-5555'] > assert [] == ['555-394-2930', '555-555-5555'] [sqlobject/tests/test_auto.py:61] ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-30 21:10 Message: Logged In: YES user_id=140558 I'll recheck it, it really passed all the tests applied to the latest svn. I tell you something tomorrow. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-30 21:07 Message: Logged In: YES user_id=140558 I'll recheck it, it really passed all the tests applied to the latest svn. I tell you something tomorrow. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-30 20:57 Message: Logged In: YES user_id=4799 test_auto.py, test_auto_old.py and test_basic.py failed. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-18 19:04 Message: Logged In: YES user_id=140558 This is the final patch against latest svn, it includes everything in one single patch. It passes the tests. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-18 16:17 Message: Logged In: YES user_id=140558 Ok, I have taken my time to understand pydist, test, etc, and here I am back with the working solution :) Now the resulting SQLobject passes all the tests. I attach an incremental patch so that you can see more clearly the changes done to fix the previous one. I've needed a new method in the Style class, instanceIDAttrToAttr, that is the complementary to the already known instanceAttrToIDAttr. If you need to transform back and forth field names, you need them both. I haven't tried to port it to the latest svn yet, this is against the same release than the first patch, but it should apply more or less clearly as this are very isolated areas in the code. When I do it I'll post it here. Sorry for the delay, it has not been easy for me to understand more deeply the code and, even less, to know how the tests work :) ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-03 15:18 Message: Logged In: YES user_id=140558 It fails because the test is not right, it still has the ID postfix hardcoded. My fault, I did no send a patch for tests. This is the piece that fails: # Select by usual way s = TestWorkKey.selectBy(composerID=c.id, title='Symphony No. 9') I have not looked at tests until now, but it looks like there should be tests for the different provides styles, in this case, if you accept the patch, at least a test for the LongStyle provided and for the current naming styles. I'll try to cook up something, but it can take a little time. Any guidelines will be appreciated (I've just read the docs ;) ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-03 14:23 Message: Logged In: YES user_id=4799 test_selectBy_foreignKey.py fails: def test1(): setupClass([TestComposerKey, TestWorkKey]) c = TestComposerKey(name='Mahler, Gustav') > w1 = TestWorkKey(composer=c, title='Symphony No. 9') [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/tests/test_selectBy_foreignKey.py:19] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def __init__(self, **kw): # The get() classmethod/constructor uses a magic keyword # argument when it wants an empty object, fetched from the # database. So we have nothing more to do in that case: if kw.has_key('_SO_fetch_no_create'): return post_funcs = [] self.sqlmeta.send(events.RowCreateSignal, kw, post_funcs) # Pass the connection object along if we were given one. if kw.has_key('connection'): self._connection = kw['connection'] self.sqlmeta._perConnection = True del kw['connection'] self._SO_writeLock = threading.Lock() if kw.has_key('id'): id = self.sqlmeta.idType(kw['id']) del kw['id'] else: id = None > self._create(id, **kw) [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/main.py:1210] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _create(self, id, **kw): self.sqlmeta._creating = True self._SO_createValues = {} self._SO_validatorState = SQLObjectState(self) # First we do a little fix-up on the keywords we were # passed: for column in self.sqlmeta.columnList: # Then we check if the column wasn't passed in, and # if not we try to get the default. if not kw.has_key(column.name) and not kw.has_key(column.foreignName): default = column.default # If we don't get it, it's an error: if default is NoDefault: E raise TypeError, "%s() did not get expected keyword argument %s" % (self.__class__.__name__, column.name) > TypeError: TestWorkKey() did not get expected keyword argument composerID [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/main.py:1231] - - - - - - - - - - - - - test1: recorded stdout - - - - - - - - - - - - - - 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/Query : CREATE TABLE test_composer_key ( id SERIAL PRIMARY KEY, name TEXT ) 1/QueryR : CREATE TABLE test_composer_key ( id SERIAL PRIMARY KEY, name TEXT ) 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/Query : CREATE TABLE test_work_key ( work_id SERIAL PRIMARY KEY, composer_id INT, title TEXT ) 1/QueryR : CREATE TABLE test_work_key ( work_id SERIAL PRIMARY KEY, composer_id INT, title TEXT ) 1/COMMIT : auto 1/Query : ALTER TABLE test_work_key ADD CONSTRAINT composer_id_exists FOREIGN KEY (composer_id) REFERENCES test_composer_key (id) 1/QueryR : ALTER TABLE test_work_key ADD CONSTRAINT composer_id_exists FOREIGN KEY (composer_id) REFERENCES test_composer_key (id) 1/COMMIT : auto 1/QueryIns: INSERT INTO test_composer_key (id, name) VALUES (1, 'Mahler, Gustav') 1/COMMIT : auto 1/QueryOne: SELECT name FROM test_composer_key WHERE id = 1 1/QueryR : SELECT name FROM test_composer_key WHERE id = 1 1/COMMIT : auto ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1353728&group_id=74338 |
|
From: <sub...@co...> - 2006-02-17 15:51:56
|
Author: phd
Date: 2006-02-17 08:51:50 -0700 (Fri, 17 Feb 2006)
New Revision: 1608
Modified:
home/phd/SQLObject/paramstyles/sqlobject/col.py
home/phd/SQLObject/paramstyles/sqlobject/joins.py
home/phd/SQLObject/paramstyles/sqlobject/main.py
home/phd/SQLObject/paramstyles/sqlobject/styles.py
home/phd/SQLObject/paramstyles/sqlobject/tests/test_auto.py
home/phd/SQLObject/paramstyles/sqlobject/tests/test_auto_old.py
Log:
Merged patches from the revisions 1606:1606 from the trunk: applied the patch 1353728: define foreign keys in Style.
Modified: home/phd/SQLObject/paramstyles/sqlobject/col.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/col.py 2006-02-17 15:50:51 UTC (rev 1607)
+++ home/phd/SQLObject/paramstyles/sqlobject/col.py 2006-02-17 15:51:50 UTC (rev 1608)
@@ -176,14 +176,18 @@
self._default = default
self.customSQLType = sqlType
+ # deal with foreign keys
self.foreignKey = foreignKey
if self.foreignKey:
- #assert self.name.upper().endswith('ID'), "All foreign key columns must end with 'ID' (%s)" % repr(self.name)
- if not self.name.upper().endswith('ID'):
+ if origName is not None:
+ idname = soClass.sqlmeta.style.instanceAttrToIDAttr(origName)
+ else:
+ idname = soClass.sqlmeta.style.instanceAttrToIDAttr(name)
+ if self.name != idname:
self.foreignName = self.name
- self.name = self.name + "ID"
+ self.name = idname
else:
- self.foreignName = self.name[:-2]
+ self.foreignName = soClass.sqlmeta.style.instanceIDAttrToAttr(self.name)
else:
self.foreignName = None
@@ -261,8 +265,7 @@
default = property(_get_default, None, None)
def _get_joinName(self):
- assert self.name[-2:] == 'ID'
- return self.name[:-2]
+ return self.soClass.sqlmeta.style.instanceIDAttrToAttr(self.name)
joinName = property(_get_joinName, None, None)
def __repr__(self):
@@ -719,8 +722,7 @@
kw['name'] = style.instanceAttrToIDAttr(style.pythonClassToAttr(foreignKey))
else:
kw['origName'] = kw['name']
- if not kw['name'].upper().endswith('ID'):
- kw['name'] = style.instanceAttrToIDAttr(kw['name'])
+ kw['name'] = style.instanceAttrToIDAttr(kw['name'])
super(SOForeignKey, self).__init__(**kw)
def postgresCreateSQL(self):
Modified: home/phd/SQLObject/paramstyles/sqlobject/joins.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/joins.py 2006-02-17 15:50:51 UTC (rev 1607)
+++ home/phd/SQLObject/paramstyles/sqlobject/joins.py 2006-02-17 15:51:50 UTC (rev 1608)
@@ -275,12 +275,8 @@
if not self.makeDefault:
return None
else:
- kw = {pythonColumn[:-2]: inst} # skipping the ID (from foreignkeyID)
+ kw = {self.soClass.sqlmeta.style.instanceIDAttrToAttr(pythonColumn): inst}
return self.otherClass(**kw) # instanciating the otherClass with all
- # values to their defaults, except the foreign key
- # TODO I don't think this is the best way to know the column as foreignKey
- # reather than foreignKeyID, but I don't found a sqlmeta.style function
- # to do the work, if there isn't such function, I must create it.
else:
return results[0]
Modified: home/phd/SQLObject/paramstyles/sqlobject/main.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/main.py 2006-02-17 15:50:51 UTC (rev 1607)
+++ home/phd/SQLObject/paramstyles/sqlobject/main.py 2006-02-17 15:51:50 UTC (rev 1608)
@@ -379,10 +379,10 @@
# SQLObject instance.
if column.foreignKey:
- # We go through the standard _SO_get_columnName
- # deal, except chopping off the "ID" ending since
+ # We go through the standard _SO_get_columnName deal
# we're giving the object, not the ID of the
# object this time:
+ origName = column.origName
if sqlmeta.cacheValues:
# self._SO_class_className is a reference
# to the class in question.
@@ -390,26 +390,21 @@
else:
# Same non-caching version as above.
getter = eval('lambda self: self._SO_foreignKey(self._SO_getValue(%s), self._SO_class_%s)' % (repr(name), column.foreignKey))
- if column.origName.upper().endswith('ID'):
- origName = column.origName[:-2]
- else:
- origName = column.origName
setattr(soClass, rawGetterName(origName), getter)
# And we set the _get_columnName version
- # (sans ID ending)
- if not hasattr(soClass, getterName(name)[:-2]):
- setattr(soClass, getterName(name)[:-2], getter)
- sqlmeta._plainForeignGetters[name[:-2]] = 1
+ if not hasattr(soClass, getterName(origName)):
+ setattr(soClass, getterName(origName), getter)
+ sqlmeta._plainForeignGetters[origName] = 1
if not column.immutable:
# The setter just gets the ID of the object,
# and then sets the real column.
setter = eval('lambda self, val: setattr(self, %s, self._SO_getID(val))' % (repr(name)))
- setattr(soClass, rawSetterName(name)[:-2], setter)
- if not hasattr(soClass, setterName(name)[:-2]):
- setattr(soClass, setterName(name)[:-2], setter)
- sqlmeta._plainForeignSetters[name[:-2]] = 1
+ setattr(soClass, rawSetterName(origName), setter)
+ if not hasattr(soClass, setterName(origName)):
+ setattr(soClass, setterName(origName), setter)
+ sqlmeta._plainForeignSetters[origName] = 1
classregistry.registry(sqlmeta.registry).addClassCallback(
column.foreignKey,
@@ -468,12 +463,12 @@
if sqlmeta._plainSetters.has_key(name):
delattr(soClass, setterName(name))
if column.foreignKey:
- delattr(soClass, rawGetterName(name)[:-2])
- if sqlmeta._plainForeignGetters.has_key(name[:-2]):
- delattr(soClass, getterName(name)[:-2])
- delattr(soClass, rawSetterName(name)[:-2])
- if sqlmeta._plainForeignSetters.has_key(name[:-2]):
- delattr(soClass, setterName(name)[:-2])
+ delattr(soClass, rawGetterName(soClass.sqlmeta.style.instanceIDAttrToAttr(name)))
+ if sqlmeta._plainForeignGetters.has_key(name):
+ delattr(soClass, getterName(name))
+ delattr(soClass, rawSetterName(soClass.sqlmeta.style.instanceIDAttrToAttr(name)))
+ if sqlmeta._plainForeignSetters.has_key(name):
+ delattr(soClass, setterName(name))
if column.alternateMethodName:
delattr(soClass, column.alternateMethodName)
Modified: home/phd/SQLObject/paramstyles/sqlobject/styles.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/styles.py 2006-02-17 15:50:51 UTC (rev 1607)
+++ home/phd/SQLObject/paramstyles/sqlobject/styles.py 2006-02-17 15:51:50 UTC (rev 1608)
@@ -54,10 +54,11 @@
return lowerword(className)
def instanceAttrToIDAttr(self, attr):
- # @@: Right now, because of how names are created for foreign
- # keys, you can't really change this style.
return attr + "ID"
+ def instanceIDAttrToAttr(self, attr):
+ return attr[:-2]
+
def tableReference(self, table):
return table + "_id"
Modified: home/phd/SQLObject/paramstyles/sqlobject/tests/test_auto.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/tests/test_auto.py 2006-02-17 15:50:51 UTC (rev 1607)
+++ home/phd/SQLObject/paramstyles/sqlobject/tests/test_auto.py 2006-02-17 15:51:50 UTC (rev 1608)
@@ -47,7 +47,7 @@
Person.sqlmeta.delColumn(nickname, changeSchema=True)
def test_dynamicJoin(self):
- col = KeyCol('personID', foreignKey='Person')
+ col = KeyCol('person', foreignKey='Person')
Phone.sqlmeta.addColumn(col, changeSchema=True)
join = MultipleJoin('Phone')
Person.sqlmeta.addJoin(join)
Modified: home/phd/SQLObject/paramstyles/sqlobject/tests/test_auto_old.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/tests/test_auto_old.py 2006-02-17 15:50:51 UTC (rev 1607)
+++ home/phd/SQLObject/paramstyles/sqlobject/tests/test_auto_old.py 2006-02-17 15:51:50 UTC (rev 1608)
@@ -49,7 +49,7 @@
OldPerson.delColumn(nickname, changeSchema=True)
def test_dynamicJoin(self):
- col = KeyCol('oldPersonID', foreignKey='OldPerson')
+ col = KeyCol('oldPerson', foreignKey='OldPerson')
OldPhone.addColumn(col, changeSchema=True)
join = MultipleJoin('OldPhone')
OldPerson.addJoin(join)
|
|
From: <sub...@co...> - 2006-02-17 15:51:05
|
Author: phd
Date: 2006-02-17 08:50:51 -0700 (Fri, 17 Feb 2006)
New Revision: 1607
Modified:
SQLObject/trunk/sqlobject/col.py
SQLObject/trunk/sqlobject/joins.py
SQLObject/trunk/sqlobject/main.py
SQLObject/trunk/sqlobject/styles.py
SQLObject/trunk/sqlobject/tests/test_auto.py
SQLObject/trunk/sqlobject/tests/test_auto_old.py
Log:
Applied the patch 1353728: define foreign keys in Style.
Modified: SQLObject/trunk/sqlobject/col.py
===================================================================
--- SQLObject/trunk/sqlobject/col.py 2006-02-17 10:11:19 UTC (rev 1606)
+++ SQLObject/trunk/sqlobject/col.py 2006-02-17 15:50:51 UTC (rev 1607)
@@ -176,14 +176,18 @@
self._default = default
self.customSQLType = sqlType
+ # deal with foreign keys
self.foreignKey = foreignKey
if self.foreignKey:
- #assert self.name.upper().endswith('ID'), "All foreign key columns must end with 'ID' (%s)" % repr(self.name)
- if not self.name.upper().endswith('ID'):
+ if origName is not None:
+ idname = soClass.sqlmeta.style.instanceAttrToIDAttr(origName)
+ else:
+ idname = soClass.sqlmeta.style.instanceAttrToIDAttr(name)
+ if self.name != idname:
self.foreignName = self.name
- self.name = self.name + "ID"
+ self.name = idname
else:
- self.foreignName = self.name[:-2]
+ self.foreignName = soClass.sqlmeta.style.instanceIDAttrToAttr(self.name)
else:
self.foreignName = None
@@ -261,8 +265,7 @@
default = property(_get_default, None, None)
def _get_joinName(self):
- assert self.name[-2:] == 'ID'
- return self.name[:-2]
+ return self.soClass.sqlmeta.style.instanceIDAttrToAttr(self.name)
joinName = property(_get_joinName, None, None)
def __repr__(self):
@@ -719,8 +722,7 @@
kw['name'] = style.instanceAttrToIDAttr(style.pythonClassToAttr(foreignKey))
else:
kw['origName'] = kw['name']
- if not kw['name'].upper().endswith('ID'):
- kw['name'] = style.instanceAttrToIDAttr(kw['name'])
+ kw['name'] = style.instanceAttrToIDAttr(kw['name'])
super(SOForeignKey, self).__init__(**kw)
def postgresCreateSQL(self):
Modified: SQLObject/trunk/sqlobject/joins.py
===================================================================
--- SQLObject/trunk/sqlobject/joins.py 2006-02-17 10:11:19 UTC (rev 1606)
+++ SQLObject/trunk/sqlobject/joins.py 2006-02-17 15:50:51 UTC (rev 1607)
@@ -275,12 +275,8 @@
if not self.makeDefault:
return None
else:
- kw = {pythonColumn[:-2]: inst} # skipping the ID (from foreignkeyID)
+ kw = {self.soClass.sqlmeta.style.instanceIDAttrToAttr(pythonColumn): inst}
return self.otherClass(**kw) # instanciating the otherClass with all
- # values to their defaults, except the foreign key
- # TODO I don't think this is the best way to know the column as foreignKey
- # reather than foreignKeyID, but I don't found a sqlmeta.style function
- # to do the work, if there isn't such function, I must create it.
else:
return results[0]
Modified: SQLObject/trunk/sqlobject/main.py
===================================================================
--- SQLObject/trunk/sqlobject/main.py 2006-02-17 10:11:19 UTC (rev 1606)
+++ SQLObject/trunk/sqlobject/main.py 2006-02-17 15:50:51 UTC (rev 1607)
@@ -379,10 +379,10 @@
# SQLObject instance.
if column.foreignKey:
- # We go through the standard _SO_get_columnName
- # deal, except chopping off the "ID" ending since
+ # We go through the standard _SO_get_columnName deal
# we're giving the object, not the ID of the
# object this time:
+ origName = column.origName
if sqlmeta.cacheValues:
# self._SO_class_className is a reference
# to the class in question.
@@ -390,26 +390,21 @@
else:
# Same non-caching version as above.
getter = eval('lambda self: self._SO_foreignKey(self._SO_getValue(%s), self._SO_class_%s)' % (repr(name), column.foreignKey))
- if column.origName.upper().endswith('ID'):
- origName = column.origName[:-2]
- else:
- origName = column.origName
setattr(soClass, rawGetterName(origName), getter)
# And we set the _get_columnName version
- # (sans ID ending)
- if not hasattr(soClass, getterName(name)[:-2]):
- setattr(soClass, getterName(name)[:-2], getter)
- sqlmeta._plainForeignGetters[name[:-2]] = 1
+ if not hasattr(soClass, getterName(origName)):
+ setattr(soClass, getterName(origName), getter)
+ sqlmeta._plainForeignGetters[origName] = 1
if not column.immutable:
# The setter just gets the ID of the object,
# and then sets the real column.
setter = eval('lambda self, val: setattr(self, %s, self._SO_getID(val))' % (repr(name)))
- setattr(soClass, rawSetterName(name)[:-2], setter)
- if not hasattr(soClass, setterName(name)[:-2]):
- setattr(soClass, setterName(name)[:-2], setter)
- sqlmeta._plainForeignSetters[name[:-2]] = 1
+ setattr(soClass, rawSetterName(origName), setter)
+ if not hasattr(soClass, setterName(origName)):
+ setattr(soClass, setterName(origName), setter)
+ sqlmeta._plainForeignSetters[origName] = 1
classregistry.registry(sqlmeta.registry).addClassCallback(
column.foreignKey,
@@ -468,12 +463,12 @@
if sqlmeta._plainSetters.has_key(name):
delattr(soClass, setterName(name))
if column.foreignKey:
- delattr(soClass, rawGetterName(name)[:-2])
- if sqlmeta._plainForeignGetters.has_key(name[:-2]):
- delattr(soClass, getterName(name)[:-2])
- delattr(soClass, rawSetterName(name)[:-2])
- if sqlmeta._plainForeignSetters.has_key(name[:-2]):
- delattr(soClass, setterName(name)[:-2])
+ delattr(soClass, rawGetterName(soClass.sqlmeta.style.instanceIDAttrToAttr(name)))
+ if sqlmeta._plainForeignGetters.has_key(name):
+ delattr(soClass, getterName(name))
+ delattr(soClass, rawSetterName(soClass.sqlmeta.style.instanceIDAttrToAttr(name)))
+ if sqlmeta._plainForeignSetters.has_key(name):
+ delattr(soClass, setterName(name))
if column.alternateMethodName:
delattr(soClass, column.alternateMethodName)
Modified: SQLObject/trunk/sqlobject/styles.py
===================================================================
--- SQLObject/trunk/sqlobject/styles.py 2006-02-17 10:11:19 UTC (rev 1606)
+++ SQLObject/trunk/sqlobject/styles.py 2006-02-17 15:50:51 UTC (rev 1607)
@@ -54,10 +54,11 @@
return lowerword(className)
def instanceAttrToIDAttr(self, attr):
- # @@: Right now, because of how names are created for foreign
- # keys, you can't really change this style.
return attr + "ID"
+ def instanceIDAttrToAttr(self, attr):
+ return attr[:-2]
+
def tableReference(self, table):
return table + "_id"
Modified: SQLObject/trunk/sqlobject/tests/test_auto.py
===================================================================
--- SQLObject/trunk/sqlobject/tests/test_auto.py 2006-02-17 10:11:19 UTC (rev 1606)
+++ SQLObject/trunk/sqlobject/tests/test_auto.py 2006-02-17 15:50:51 UTC (rev 1607)
@@ -47,7 +47,7 @@
Person.sqlmeta.delColumn(nickname, changeSchema=True)
def test_dynamicJoin(self):
- col = KeyCol('personID', foreignKey='Person')
+ col = KeyCol('person', foreignKey='Person')
Phone.sqlmeta.addColumn(col, changeSchema=True)
join = MultipleJoin('Phone')
Person.sqlmeta.addJoin(join)
Modified: SQLObject/trunk/sqlobject/tests/test_auto_old.py
===================================================================
--- SQLObject/trunk/sqlobject/tests/test_auto_old.py 2006-02-17 10:11:19 UTC (rev 1606)
+++ SQLObject/trunk/sqlobject/tests/test_auto_old.py 2006-02-17 15:50:51 UTC (rev 1607)
@@ -49,7 +49,7 @@
OldPerson.delColumn(nickname, changeSchema=True)
def test_dynamicJoin(self):
- col = KeyCol('oldPersonID', foreignKey='OldPerson')
+ col = KeyCol('oldPerson', foreignKey='OldPerson')
OldPhone.addColumn(col, changeSchema=True)
join = MultipleJoin('OldPhone')
OldPerson.addJoin(join)
|
|
From: SourceForge.net <no...@so...> - 2006-02-17 15:49:12
|
Patches item #1353728, was opened at 2005-11-11 08:20 Message generated for change (Comment added) made by linux4u You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1353728&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: Invalid Priority: 5 Submitted By: Pau Aliagas (linux4u) Assigned to: Oleg Broytmann (phd) Summary: define foreign keys in Style Initial Comment: I don't like to use attrID all along the code to access related tables, I want to be able use the nomeclature I like taking advantage of the nice Style idea. This is especially true when you create RelatedJoins when you use a nomeclature like I do (table.id_table), but it's the same for all the nomeclatures you can imagine. In styles.py it warns: def instanceAttrToIDAttr(self, attr): # @@: Right now, because of how names are created for foreign # keys, you can't really change this style. return attr + "ID" With this patch you can define how you want the foreign keys generated, they won't be mandatorily generated as attrID. Example: class LongStyle(Style): """ This style is derived from Style, that does not do any translation, but constructs the table ids like id_table. """ def instanceAttrToIDAttr(self, attr): return "id_" + attr def tableReference(self, table): # str.rsplit is python 2.4+ only if version_info >= (2, 4): return "id_" + table.rsplit(".", 1)[-1] else: return "id_" + rsplit(table, ".", 1)[-1] class mm_server(SQLObject): class sqlmeta: table = "smsarena.mm_server" style = LongStyle(longID = True) _connection = conn_smsarena server = StringCol(alternateID = True, varchar = True, length = 255, alternateMethodName = "by_server") tz = StringCol(length = 20, default = 'CET', notNone = True) conutry_code = StringCol(length = 2, varchar = False, default = '', notNone = True) # until now I had to do this # mm_server_aliases = SQLMultipleJoin("mm_server_alias", joinColumn = "mm_serverID", orderBy = "server") # now it's perfect! mm_server_aliases = SQLMultipleJoin("mm_server_alias", orderBy = "server") class mm_server_alias(SQLObject): class sqlmeta: table = "smsarena.mm_server_alias" style = LongStyle(longID = True) _connection = conn_smsarena # until now I had to do this # mm_server = ForeignKey("mm_server", dbName = "id_mm_server") mm_server = ForeignKey("mm_server") server = StringCol(alternateID = True, varchar = True, length = 255, alternateMethodName = "by_server") I hope it's clear :) Pau ---------------------------------------------------------------------- >Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 16:49 Message: Logged In: YES user_id=140558 After fixing my patch (I'm sure it works now!!) I'm reviewing the tests that fail. See the attached file "failed tests 2006-01-17 version 1" for the tests an the detailed explanations. In summary: test_ForeignKey.py: you know about it, it fails in all the databases test_SQLMultipleJoin.py: I don't see why it fails, it fails in sqlite and mysql, not in pgsql * sqlite * my problem is that sqlite-3.1.2 does not support alter tabble ad column, so no problem. * mysql * test_datetime.py ---------------- to_python does not seem to work as expected. test_enum.py ------------ BLOB/TEXT column indexes require length in mysql I hope that this makes clear the current status. If you accept the current patch, maybe we could open another ticket with the current bugs in mysql and sqlite, as these are clearly separate issues. Thanks ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 14:26 Message: Logged In: YES user_id=140558 I've fixed the problems with addColumns and delColum, now it passes the tests (not the ones that fail I do not why). I've fixed the tests too: I think we should NOT add the columns with ID at the end as the style add it for you. Otherwise I should modify the sytle functions to conditionally check if they end in ID.... I don't think that it is ok, if we want that, we define anthjer style that removes double ID at the end. This is internal to the style and so should be kept. Hope it's ok now :) ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 14:01 Message: Logged In: YES user_id=140558 These are my versions (ignore my comment in the other patch ticket, my misake): mysql-4.1.16-1.FC4.1 postgresql-8.0.7-1.FC4.1 python-psycopg-1.1.21-1.fc4 python-sqlite-1.1.6-1 sqlite-3.1.2-3 ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 13:38 Message: Logged In: YES user_id=4799 Except for the problem i test_ForeignKey.py that I know about... others look pretty strange. Let look at the environment. What DB versions? MySQL, PgSQL, SQLite? Drivers versions? MySQLdb, psycopg, PySQLite? MyPostgres is 7.4, psycopg 1.1.21 and 2.0b5. PySQLite 1.1.7 and 2.1.3. A week ago I upgarded to SQLite 3.3.3 and PySQLite 2.1.3; that eliminated some minor problems with patches I have had with SQLIte 2.8.0 and PySQLite 2.1.0. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 13:11 Message: Logged In: YES user_id=140558 Ok, plain SQLObject from SVN now, no patch. There are tests that fail for me in current SQLObject in mysql, postgres and sqlite. I attach them all. This is a fully updated Fedora 4. I've made the tests in mysql and there are some thet do not pass. I enclose the results and a file where I comment why the fail and a possible solution. The tests that fail in postgres and sqlite are the ones I've already reported (mnore or less). Any help? ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 10:22 Message: Logged In: YES user_id=4799 No, the latest SQLObject passes all tests (how would I commit your other patch if a test fail?) except for minor glitch in test_ForeignKey.py which I'm going to resolve RSN. test_auto.py certainly pass. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 10:13 Message: Logged In: YES user_id=140558 I've run the test with the latest SQLObject (no extra patches) and the tests fail too, at least they fail when I run them. As I explained before, there's something wrong when adding columns to sqlite, it fails and all the tests that depend on the added columns fail too. Does it happen to you too? ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-16 16:16 Message: Logged In: YES user_id=4799 These tests fail in both Postgres and SQLite. Two major backends (of 3) for SQLObject. If the problem is in tests you can patch tests, too... test_auto.py: def test_dynamicJoin(self): col = KeyCol('personID', foreignKey='Person') Phone.sqlmeta.addColumn(col, changeSchema=True) join = MultipleJoin('Phone') Person.sqlmeta.addJoin(join) for phone in Phone.select('all'): if phone.phone.startswith('555'): phone.person = Person.selectBy(name='tim')[0] else: phone.person = Person.selectBy(name='bob')[0] > l = [p.phone for p in Person.selectBy(name='tim')[0].phones] [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/test_auto.py:59] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > [failure to get at sourcelines from <TracebackEntry /home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/<string>:1>] [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/<string>:1] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def performJoin(self, inst): ids = inst._connection._SO_selectJoin( self.otherClass, self.joinColumn, > inst.id) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/joins.py:144] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _SO_selectJoin(self, soClass, column, value): return self.queryAll("SELECT %s FROM %s WHERE %s = %s" % (soClass.sqlmeta.idName, soClass.sqlmeta.table, column, > self.sqlrepr(value))) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:652] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def queryAll(self, s): > return self._runWithConnection(self._queryAll, s) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:327] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _runWithConnection(self, meth, *args): conn = self.getConnection() try: > val = meth(conn, *args) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:228] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _queryAll(self, conn, s): if self.debug: self.printDebug(conn, s, 'QueryAll') c = conn.cursor() > self._executeRetry(conn, c, s) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:320] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _executeRetry(self, conn, cursor, query): if self.debug: self.printDebug(conn, query, 'QueryR') E return cursor.execute(query) > OperationalError: no such column: person_id [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:306] - - - - - - - - - - - test_dynamicJoin: recorded stdout - - - - - - - - - - - 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/Query : DELETE FROM person 1/QueryR : DELETE FROM person 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/Query : DELETE FROM phone 1/QueryR : DELETE FROM phone 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('jane') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 1 1/QueryR : SELECT name_col FROM person WHERE id = 1 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('tim') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 2 1/QueryR : SELECT name_col FROM person WHERE id = 2 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('bob') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 3 1/QueryR : SELECT name_col FROM person WHERE id = 3 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('jake') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 4 1/QueryR : SELECT name_col FROM person WHERE id = 4 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('555-555-5555') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 1 1/QueryR : SELECT phone FROM phone WHERE id = 1 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('555-394-2930') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 2 1/QueryR : SELECT phone FROM phone WHERE id = 2 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('444-382-4854') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 3 1/QueryR : SELECT phone FROM phone WHERE id = 3 1/COMMIT : auto 1/Query : ALTER TABLE phone ADD COLUMN person_i_d_id INT 1/QueryR : ALTER TABLE phone ADD COLUMN person_i_d_id INT 1/COMMIT : auto 1/Select : SELECT phone.id, phone.phone, phone.person_i_d_id FROM phone WHERE 1 = 1 ORDER BY phone 1/QueryR : SELECT phone.id, phone.phone, phone.person_i_d_id FROM phone WHERE 1 = 1 ORDER BY phone 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'bob' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'bob' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/QueryAll: SELECT id FROM phone WHERE person_id = 2 1/QueryR : SELECT id FROM phone WHERE person_id = 2 1/COMMIT : auto ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-15 16:54 Message: Logged In: YES user_id=140558 Ok, here I go again. I've fixed a small bug: the name of the field was not porperly set when using Key(foreignKey... instead of ForeignKey. This fixes test_basic. And I think that there is nothing else to fix, I'm probably wrong, but I'll explain it hera. test_auto_old.py... FAIL test_auto.py... FAIL test_foreignKey.py... FAIL These tests fail because sqlite is failing when adding columns. In mysql it does not fail. I do not think it's this patch fault. And finally: test_SQLMultipleJoin.py... FAIL E assert str(hibrid.fightersAsSResult.sum('power')) == '23' > assert '23.0' == '23' + where '23.0' = str(23.0) + where 23.0 = <Race 3 name="'hibrid (human wi...'">.fightersAsSResult.sum('power') Again this is an error in the test. Please let me know if it can go in now :) If you can have a quick look at it better, it takes time to restart ths tests, I'd rather do it before I move on to another thing. Thanks Pau ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-14 10:05 Message: Logged In: YES user_id=140558 Oleg, I've posted to the list because I run the tests and pass. I'm sure I'm doing something wrong but I don't see what. I lost more than 3 hours yesterday just trying to run te tests :( I printed things in dbtest.py and say that TESTDB did not change anything. I chenged manually conftest.py because I ahd a message that yoiu need sqlite2 for memory databases, but still I'm not sure everything works becasue I pass al the tests. Can you help me, I want to close this patch soon and move to other improvements but this is being much more difficult than it should. Thanks a lot Pau ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-09 17:42 Message: Logged In: YES user_id=140558 I'm very busy but again will try to find some time to fix it. I'm using it every day without a glitch, even using the clause attributes like in the Complex example (new type of joins *toMany). I'll update it to latest SVN just in case this is the problem, I did it with that day's current. Please do not close it, I really intend to pass the tests, I'm already using it. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-09 17:11 Message: Logged In: YES user_id=4799 test_auto.py, for example fails: def test_dynamicJoin(self): col = KeyCol('personID', foreignKey='Person') Phone.sqlmeta.addColumn(col, changeSchema=True) join = MultipleJoin('Phone') Person.sqlmeta.addJoin(join) for phone in Phone.select('all'): if phone.phone.startswith('555'): phone.person = Person.selectBy(name='tim')[0] else: phone.person = Person.selectBy(name='bob')[0] l = [p.phone for p in Person.selectBy(name='tim')[0].phones] l.sort() E assert l == ['555-394-2930', '555-555-5555'] > assert [] == ['555-394-2930', '555-555-5555'] [sqlobject/tests/test_auto.py:61] ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-30 19:10 Message: Logged In: YES user_id=140558 I'll recheck it, it really passed all the tests applied to the latest svn. I tell you something tomorrow. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-30 19:07 Message: Logged In: YES user_id=140558 I'll recheck it, it really passed all the tests applied to the latest svn. I tell you something tomorrow. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-30 18:57 Message: Logged In: YES user_id=4799 test_auto.py, test_auto_old.py and test_basic.py failed. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-18 17:04 Message: Logged In: YES user_id=140558 This is the final patch against latest svn, it includes everything in one single patch. It passes the tests. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-18 14:17 Message: Logged In: YES user_id=140558 Ok, I have taken my time to understand pydist, test, etc, and here I am back with the working solution :) Now the resulting SQLobject passes all the tests. I attach an incremental patch so that you can see more clearly the changes done to fix the previous one. I've needed a new method in the Style class, instanceIDAttrToAttr, that is the complementary to the already known instanceAttrToIDAttr. If you need to transform back and forth field names, you need them both. I haven't tried to port it to the latest svn yet, this is against the same release than the first patch, but it should apply more or less clearly as this are very isolated areas in the code. When I do it I'll post it here. Sorry for the delay, it has not been easy for me to understand more deeply the code and, even less, to know how the tests work :) ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-03 13:18 Message: Logged In: YES user_id=140558 It fails because the test is not right, it still has the ID postfix hardcoded. My fault, I did no send a patch for tests. This is the piece that fails: # Select by usual way s = TestWorkKey.selectBy(composerID=c.id, title='Symphony No. 9') I have not looked at tests until now, but it looks like there should be tests for the different provides styles, in this case, if you accept the patch, at least a test for the LongStyle provided and for the current naming styles. I'll try to cook up something, but it can take a little time. Any guidelines will be appreciated (I've just read the docs ;) ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-03 12:23 Message: Logged In: YES user_id=4799 test_selectBy_foreignKey.py fails: def test1(): setupClass([TestComposerKey, TestWorkKey]) c = TestComposerKey(name='Mahler, Gustav') > w1 = TestWorkKey(composer=c, title='Symphony No. 9') [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/tests/test_selectBy_foreignKey.py:19] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def __init__(self, **kw): # The get() classmethod/constructor uses a magic keyword # argument when it wants an empty object, fetched from the # database. So we have nothing more to do in that case: if kw.has_key('_SO_fetch_no_create'): return post_funcs = [] self.sqlmeta.send(events.RowCreateSignal, kw, post_funcs) # Pass the connection object along if we were given one. if kw.has_key('connection'): self._connection = kw['connection'] self.sqlmeta._perConnection = True del kw['connection'] self._SO_writeLock = threading.Lock() if kw.has_key('id'): id = self.sqlmeta.idType(kw['id']) del kw['id'] else: id = None > self._create(id, **kw) [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/main.py:1210] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _create(self, id, **kw): self.sqlmeta._creating = True self._SO_createValues = {} self._SO_validatorState = SQLObjectState(self) # First we do a little fix-up on the keywords we were # passed: for column in self.sqlmeta.columnList: # Then we check if the column wasn't passed in, and # if not we try to get the default. if not kw.has_key(column.name) and not kw.has_key(column.foreignName): default = column.default # If we don't get it, it's an error: if default is NoDefault: E raise TypeError, "%s() did not get expected keyword argument %s" % (self.__class__.__name__, column.name) > TypeError: TestWorkKey() did not get expected keyword argument composerID [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/main.py:1231] - - - - - - - - - - - - - test1: recorded stdout - - - - - - - - - - - - - - 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/Query : CREATE TABLE test_composer_key ( id SERIAL PRIMARY KEY, name TEXT ) 1/QueryR : CREATE TABLE test_composer_key ( id SERIAL PRIMARY KEY, name TEXT ) 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/Query : CREATE TABLE test_work_key ( work_id SERIAL PRIMARY KEY, composer_id INT, title TEXT ) 1/QueryR : CREATE TABLE test_work_key ( work_id SERIAL PRIMARY KEY, composer_id INT, title TEXT ) 1/COMMIT : auto 1/Query : ALTER TABLE test_work_key ADD CONSTRAINT composer_id_exists FOREIGN KEY (composer_id) REFERENCES test_composer_key (id) 1/QueryR : ALTER TABLE test_work_key ADD CONSTRAINT composer_id_exists FOREIGN KEY (composer_id) REFERENCES test_composer_key (id) 1/COMMIT : auto 1/QueryIns: INSERT INTO test_composer_key (id, name) VALUES (1, 'Mahler, Gustav') 1/COMMIT : auto 1/QueryOne: SELECT name FROM test_composer_key WHERE id = 1 1/QueryR : SELECT name FROM test_composer_key WHERE id = 1 1/COMMIT : auto ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1353728&group_id=74338 |
|
From: SourceForge.net <no...@so...> - 2006-02-17 13:26:47
|
Patches item #1353728, was opened at 2005-11-11 08:20 Message generated for change (Comment added) made by linux4u You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1353728&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: Invalid Priority: 5 Submitted By: Pau Aliagas (linux4u) Assigned to: Oleg Broytmann (phd) Summary: define foreign keys in Style Initial Comment: I don't like to use attrID all along the code to access related tables, I want to be able use the nomeclature I like taking advantage of the nice Style idea. This is especially true when you create RelatedJoins when you use a nomeclature like I do (table.id_table), but it's the same for all the nomeclatures you can imagine. In styles.py it warns: def instanceAttrToIDAttr(self, attr): # @@: Right now, because of how names are created for foreign # keys, you can't really change this style. return attr + "ID" With this patch you can define how you want the foreign keys generated, they won't be mandatorily generated as attrID. Example: class LongStyle(Style): """ This style is derived from Style, that does not do any translation, but constructs the table ids like id_table. """ def instanceAttrToIDAttr(self, attr): return "id_" + attr def tableReference(self, table): # str.rsplit is python 2.4+ only if version_info >= (2, 4): return "id_" + table.rsplit(".", 1)[-1] else: return "id_" + rsplit(table, ".", 1)[-1] class mm_server(SQLObject): class sqlmeta: table = "smsarena.mm_server" style = LongStyle(longID = True) _connection = conn_smsarena server = StringCol(alternateID = True, varchar = True, length = 255, alternateMethodName = "by_server") tz = StringCol(length = 20, default = 'CET', notNone = True) conutry_code = StringCol(length = 2, varchar = False, default = '', notNone = True) # until now I had to do this # mm_server_aliases = SQLMultipleJoin("mm_server_alias", joinColumn = "mm_serverID", orderBy = "server") # now it's perfect! mm_server_aliases = SQLMultipleJoin("mm_server_alias", orderBy = "server") class mm_server_alias(SQLObject): class sqlmeta: table = "smsarena.mm_server_alias" style = LongStyle(longID = True) _connection = conn_smsarena # until now I had to do this # mm_server = ForeignKey("mm_server", dbName = "id_mm_server") mm_server = ForeignKey("mm_server") server = StringCol(alternateID = True, varchar = True, length = 255, alternateMethodName = "by_server") I hope it's clear :) Pau ---------------------------------------------------------------------- >Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 14:26 Message: Logged In: YES user_id=140558 I've fixed the problems with addColumns and delColum, now it passes the tests (not the ones that fail I do not why). I've fixed the tests too: I think we should NOT add the columns with ID at the end as the style add it for you. Otherwise I should modify the sytle functions to conditionally check if they end in ID.... I don't think that it is ok, if we want that, we define anthjer style that removes double ID at the end. This is internal to the style and so should be kept. Hope it's ok now :) ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 14:01 Message: Logged In: YES user_id=140558 These are my versions (ignore my comment in the other patch ticket, my misake): mysql-4.1.16-1.FC4.1 postgresql-8.0.7-1.FC4.1 python-psycopg-1.1.21-1.fc4 python-sqlite-1.1.6-1 sqlite-3.1.2-3 ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 13:38 Message: Logged In: YES user_id=4799 Except for the problem i test_ForeignKey.py that I know about... others look pretty strange. Let look at the environment. What DB versions? MySQL, PgSQL, SQLite? Drivers versions? MySQLdb, psycopg, PySQLite? MyPostgres is 7.4, psycopg 1.1.21 and 2.0b5. PySQLite 1.1.7 and 2.1.3. A week ago I upgarded to SQLite 3.3.3 and PySQLite 2.1.3; that eliminated some minor problems with patches I have had with SQLIte 2.8.0 and PySQLite 2.1.0. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 13:11 Message: Logged In: YES user_id=140558 Ok, plain SQLObject from SVN now, no patch. There are tests that fail for me in current SQLObject in mysql, postgres and sqlite. I attach them all. This is a fully updated Fedora 4. I've made the tests in mysql and there are some thet do not pass. I enclose the results and a file where I comment why the fail and a possible solution. The tests that fail in postgres and sqlite are the ones I've already reported (mnore or less). Any help? ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 10:22 Message: Logged In: YES user_id=4799 No, the latest SQLObject passes all tests (how would I commit your other patch if a test fail?) except for minor glitch in test_ForeignKey.py which I'm going to resolve RSN. test_auto.py certainly pass. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 10:13 Message: Logged In: YES user_id=140558 I've run the test with the latest SQLObject (no extra patches) and the tests fail too, at least they fail when I run them. As I explained before, there's something wrong when adding columns to sqlite, it fails and all the tests that depend on the added columns fail too. Does it happen to you too? ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-16 16:16 Message: Logged In: YES user_id=4799 These tests fail in both Postgres and SQLite. Two major backends (of 3) for SQLObject. If the problem is in tests you can patch tests, too... test_auto.py: def test_dynamicJoin(self): col = KeyCol('personID', foreignKey='Person') Phone.sqlmeta.addColumn(col, changeSchema=True) join = MultipleJoin('Phone') Person.sqlmeta.addJoin(join) for phone in Phone.select('all'): if phone.phone.startswith('555'): phone.person = Person.selectBy(name='tim')[0] else: phone.person = Person.selectBy(name='bob')[0] > l = [p.phone for p in Person.selectBy(name='tim')[0].phones] [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/test_auto.py:59] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > [failure to get at sourcelines from <TracebackEntry /home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/<string>:1>] [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/<string>:1] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def performJoin(self, inst): ids = inst._connection._SO_selectJoin( self.otherClass, self.joinColumn, > inst.id) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/joins.py:144] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _SO_selectJoin(self, soClass, column, value): return self.queryAll("SELECT %s FROM %s WHERE %s = %s" % (soClass.sqlmeta.idName, soClass.sqlmeta.table, column, > self.sqlrepr(value))) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:652] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def queryAll(self, s): > return self._runWithConnection(self._queryAll, s) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:327] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _runWithConnection(self, meth, *args): conn = self.getConnection() try: > val = meth(conn, *args) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:228] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _queryAll(self, conn, s): if self.debug: self.printDebug(conn, s, 'QueryAll') c = conn.cursor() > self._executeRetry(conn, c, s) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:320] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _executeRetry(self, conn, cursor, query): if self.debug: self.printDebug(conn, query, 'QueryR') E return cursor.execute(query) > OperationalError: no such column: person_id [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:306] - - - - - - - - - - - test_dynamicJoin: recorded stdout - - - - - - - - - - - 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/Query : DELETE FROM person 1/QueryR : DELETE FROM person 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/Query : DELETE FROM phone 1/QueryR : DELETE FROM phone 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('jane') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 1 1/QueryR : SELECT name_col FROM person WHERE id = 1 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('tim') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 2 1/QueryR : SELECT name_col FROM person WHERE id = 2 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('bob') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 3 1/QueryR : SELECT name_col FROM person WHERE id = 3 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('jake') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 4 1/QueryR : SELECT name_col FROM person WHERE id = 4 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('555-555-5555') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 1 1/QueryR : SELECT phone FROM phone WHERE id = 1 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('555-394-2930') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 2 1/QueryR : SELECT phone FROM phone WHERE id = 2 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('444-382-4854') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 3 1/QueryR : SELECT phone FROM phone WHERE id = 3 1/COMMIT : auto 1/Query : ALTER TABLE phone ADD COLUMN person_i_d_id INT 1/QueryR : ALTER TABLE phone ADD COLUMN person_i_d_id INT 1/COMMIT : auto 1/Select : SELECT phone.id, phone.phone, phone.person_i_d_id FROM phone WHERE 1 = 1 ORDER BY phone 1/QueryR : SELECT phone.id, phone.phone, phone.person_i_d_id FROM phone WHERE 1 = 1 ORDER BY phone 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'bob' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'bob' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/QueryAll: SELECT id FROM phone WHERE person_id = 2 1/QueryR : SELECT id FROM phone WHERE person_id = 2 1/COMMIT : auto ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-15 16:54 Message: Logged In: YES user_id=140558 Ok, here I go again. I've fixed a small bug: the name of the field was not porperly set when using Key(foreignKey... instead of ForeignKey. This fixes test_basic. And I think that there is nothing else to fix, I'm probably wrong, but I'll explain it hera. test_auto_old.py... FAIL test_auto.py... FAIL test_foreignKey.py... FAIL These tests fail because sqlite is failing when adding columns. In mysql it does not fail. I do not think it's this patch fault. And finally: test_SQLMultipleJoin.py... FAIL E assert str(hibrid.fightersAsSResult.sum('power')) == '23' > assert '23.0' == '23' + where '23.0' = str(23.0) + where 23.0 = <Race 3 name="'hibrid (human wi...'">.fightersAsSResult.sum('power') Again this is an error in the test. Please let me know if it can go in now :) If you can have a quick look at it better, it takes time to restart ths tests, I'd rather do it before I move on to another thing. Thanks Pau ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-14 10:05 Message: Logged In: YES user_id=140558 Oleg, I've posted to the list because I run the tests and pass. I'm sure I'm doing something wrong but I don't see what. I lost more than 3 hours yesterday just trying to run te tests :( I printed things in dbtest.py and say that TESTDB did not change anything. I chenged manually conftest.py because I ahd a message that yoiu need sqlite2 for memory databases, but still I'm not sure everything works becasue I pass al the tests. Can you help me, I want to close this patch soon and move to other improvements but this is being much more difficult than it should. Thanks a lot Pau ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-09 17:42 Message: Logged In: YES user_id=140558 I'm very busy but again will try to find some time to fix it. I'm using it every day without a glitch, even using the clause attributes like in the Complex example (new type of joins *toMany). I'll update it to latest SVN just in case this is the problem, I did it with that day's current. Please do not close it, I really intend to pass the tests, I'm already using it. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-09 17:11 Message: Logged In: YES user_id=4799 test_auto.py, for example fails: def test_dynamicJoin(self): col = KeyCol('personID', foreignKey='Person') Phone.sqlmeta.addColumn(col, changeSchema=True) join = MultipleJoin('Phone') Person.sqlmeta.addJoin(join) for phone in Phone.select('all'): if phone.phone.startswith('555'): phone.person = Person.selectBy(name='tim')[0] else: phone.person = Person.selectBy(name='bob')[0] l = [p.phone for p in Person.selectBy(name='tim')[0].phones] l.sort() E assert l == ['555-394-2930', '555-555-5555'] > assert [] == ['555-394-2930', '555-555-5555'] [sqlobject/tests/test_auto.py:61] ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-30 19:10 Message: Logged In: YES user_id=140558 I'll recheck it, it really passed all the tests applied to the latest svn. I tell you something tomorrow. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-30 19:07 Message: Logged In: YES user_id=140558 I'll recheck it, it really passed all the tests applied to the latest svn. I tell you something tomorrow. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-30 18:57 Message: Logged In: YES user_id=4799 test_auto.py, test_auto_old.py and test_basic.py failed. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-18 17:04 Message: Logged In: YES user_id=140558 This is the final patch against latest svn, it includes everything in one single patch. It passes the tests. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-18 14:17 Message: Logged In: YES user_id=140558 Ok, I have taken my time to understand pydist, test, etc, and here I am back with the working solution :) Now the resulting SQLobject passes all the tests. I attach an incremental patch so that you can see more clearly the changes done to fix the previous one. I've needed a new method in the Style class, instanceIDAttrToAttr, that is the complementary to the already known instanceAttrToIDAttr. If you need to transform back and forth field names, you need them both. I haven't tried to port it to the latest svn yet, this is against the same release than the first patch, but it should apply more or less clearly as this are very isolated areas in the code. When I do it I'll post it here. Sorry for the delay, it has not been easy for me to understand more deeply the code and, even less, to know how the tests work :) ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-03 13:18 Message: Logged In: YES user_id=140558 It fails because the test is not right, it still has the ID postfix hardcoded. My fault, I did no send a patch for tests. This is the piece that fails: # Select by usual way s = TestWorkKey.selectBy(composerID=c.id, title='Symphony No. 9') I have not looked at tests until now, but it looks like there should be tests for the different provides styles, in this case, if you accept the patch, at least a test for the LongStyle provided and for the current naming styles. I'll try to cook up something, but it can take a little time. Any guidelines will be appreciated (I've just read the docs ;) ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-03 12:23 Message: Logged In: YES user_id=4799 test_selectBy_foreignKey.py fails: def test1(): setupClass([TestComposerKey, TestWorkKey]) c = TestComposerKey(name='Mahler, Gustav') > w1 = TestWorkKey(composer=c, title='Symphony No. 9') [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/tests/test_selectBy_foreignKey.py:19] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def __init__(self, **kw): # The get() classmethod/constructor uses a magic keyword # argument when it wants an empty object, fetched from the # database. So we have nothing more to do in that case: if kw.has_key('_SO_fetch_no_create'): return post_funcs = [] self.sqlmeta.send(events.RowCreateSignal, kw, post_funcs) # Pass the connection object along if we were given one. if kw.has_key('connection'): self._connection = kw['connection'] self.sqlmeta._perConnection = True del kw['connection'] self._SO_writeLock = threading.Lock() if kw.has_key('id'): id = self.sqlmeta.idType(kw['id']) del kw['id'] else: id = None > self._create(id, **kw) [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/main.py:1210] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _create(self, id, **kw): self.sqlmeta._creating = True self._SO_createValues = {} self._SO_validatorState = SQLObjectState(self) # First we do a little fix-up on the keywords we were # passed: for column in self.sqlmeta.columnList: # Then we check if the column wasn't passed in, and # if not we try to get the default. if not kw.has_key(column.name) and not kw.has_key(column.foreignName): default = column.default # If we don't get it, it's an error: if default is NoDefault: E raise TypeError, "%s() did not get expected keyword argument %s" % (self.__class__.__name__, column.name) > TypeError: TestWorkKey() did not get expected keyword argument composerID [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/main.py:1231] - - - - - - - - - - - - - test1: recorded stdout - - - - - - - - - - - - - - 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/Query : CREATE TABLE test_composer_key ( id SERIAL PRIMARY KEY, name TEXT ) 1/QueryR : CREATE TABLE test_composer_key ( id SERIAL PRIMARY KEY, name TEXT ) 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/Query : CREATE TABLE test_work_key ( work_id SERIAL PRIMARY KEY, composer_id INT, title TEXT ) 1/QueryR : CREATE TABLE test_work_key ( work_id SERIAL PRIMARY KEY, composer_id INT, title TEXT ) 1/COMMIT : auto 1/Query : ALTER TABLE test_work_key ADD CONSTRAINT composer_id_exists FOREIGN KEY (composer_id) REFERENCES test_composer_key (id) 1/QueryR : ALTER TABLE test_work_key ADD CONSTRAINT composer_id_exists FOREIGN KEY (composer_id) REFERENCES test_composer_key (id) 1/COMMIT : auto 1/QueryIns: INSERT INTO test_composer_key (id, name) VALUES (1, 'Mahler, Gustav') 1/COMMIT : auto 1/QueryOne: SELECT name FROM test_composer_key WHERE id = 1 1/QueryR : SELECT name FROM test_composer_key WHERE id = 1 1/COMMIT : auto ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1353728&group_id=74338 |
|
From: SourceForge.net <no...@so...> - 2006-02-17 13:01:34
|
Patches item #1353728, was opened at 2005-11-11 08:20 Message generated for change (Comment added) made by linux4u You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1353728&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: Invalid Priority: 5 Submitted By: Pau Aliagas (linux4u) Assigned to: Oleg Broytmann (phd) Summary: define foreign keys in Style Initial Comment: I don't like to use attrID all along the code to access related tables, I want to be able use the nomeclature I like taking advantage of the nice Style idea. This is especially true when you create RelatedJoins when you use a nomeclature like I do (table.id_table), but it's the same for all the nomeclatures you can imagine. In styles.py it warns: def instanceAttrToIDAttr(self, attr): # @@: Right now, because of how names are created for foreign # keys, you can't really change this style. return attr + "ID" With this patch you can define how you want the foreign keys generated, they won't be mandatorily generated as attrID. Example: class LongStyle(Style): """ This style is derived from Style, that does not do any translation, but constructs the table ids like id_table. """ def instanceAttrToIDAttr(self, attr): return "id_" + attr def tableReference(self, table): # str.rsplit is python 2.4+ only if version_info >= (2, 4): return "id_" + table.rsplit(".", 1)[-1] else: return "id_" + rsplit(table, ".", 1)[-1] class mm_server(SQLObject): class sqlmeta: table = "smsarena.mm_server" style = LongStyle(longID = True) _connection = conn_smsarena server = StringCol(alternateID = True, varchar = True, length = 255, alternateMethodName = "by_server") tz = StringCol(length = 20, default = 'CET', notNone = True) conutry_code = StringCol(length = 2, varchar = False, default = '', notNone = True) # until now I had to do this # mm_server_aliases = SQLMultipleJoin("mm_server_alias", joinColumn = "mm_serverID", orderBy = "server") # now it's perfect! mm_server_aliases = SQLMultipleJoin("mm_server_alias", orderBy = "server") class mm_server_alias(SQLObject): class sqlmeta: table = "smsarena.mm_server_alias" style = LongStyle(longID = True) _connection = conn_smsarena # until now I had to do this # mm_server = ForeignKey("mm_server", dbName = "id_mm_server") mm_server = ForeignKey("mm_server") server = StringCol(alternateID = True, varchar = True, length = 255, alternateMethodName = "by_server") I hope it's clear :) Pau ---------------------------------------------------------------------- >Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 14:01 Message: Logged In: YES user_id=140558 These are my versions (ignore my comment in the other patch ticket, my misake): mysql-4.1.16-1.FC4.1 postgresql-8.0.7-1.FC4.1 python-psycopg-1.1.21-1.fc4 python-sqlite-1.1.6-1 sqlite-3.1.2-3 ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 13:38 Message: Logged In: YES user_id=4799 Except for the problem i test_ForeignKey.py that I know about... others look pretty strange. Let look at the environment. What DB versions? MySQL, PgSQL, SQLite? Drivers versions? MySQLdb, psycopg, PySQLite? MyPostgres is 7.4, psycopg 1.1.21 and 2.0b5. PySQLite 1.1.7 and 2.1.3. A week ago I upgarded to SQLite 3.3.3 and PySQLite 2.1.3; that eliminated some minor problems with patches I have had with SQLIte 2.8.0 and PySQLite 2.1.0. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 13:11 Message: Logged In: YES user_id=140558 Ok, plain SQLObject from SVN now, no patch. There are tests that fail for me in current SQLObject in mysql, postgres and sqlite. I attach them all. This is a fully updated Fedora 4. I've made the tests in mysql and there are some thet do not pass. I enclose the results and a file where I comment why the fail and a possible solution. The tests that fail in postgres and sqlite are the ones I've already reported (mnore or less). Any help? ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 10:22 Message: Logged In: YES user_id=4799 No, the latest SQLObject passes all tests (how would I commit your other patch if a test fail?) except for minor glitch in test_ForeignKey.py which I'm going to resolve RSN. test_auto.py certainly pass. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 10:13 Message: Logged In: YES user_id=140558 I've run the test with the latest SQLObject (no extra patches) and the tests fail too, at least they fail when I run them. As I explained before, there's something wrong when adding columns to sqlite, it fails and all the tests that depend on the added columns fail too. Does it happen to you too? ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-16 16:16 Message: Logged In: YES user_id=4799 These tests fail in both Postgres and SQLite. Two major backends (of 3) for SQLObject. If the problem is in tests you can patch tests, too... test_auto.py: def test_dynamicJoin(self): col = KeyCol('personID', foreignKey='Person') Phone.sqlmeta.addColumn(col, changeSchema=True) join = MultipleJoin('Phone') Person.sqlmeta.addJoin(join) for phone in Phone.select('all'): if phone.phone.startswith('555'): phone.person = Person.selectBy(name='tim')[0] else: phone.person = Person.selectBy(name='bob')[0] > l = [p.phone for p in Person.selectBy(name='tim')[0].phones] [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/test_auto.py:59] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > [failure to get at sourcelines from <TracebackEntry /home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/<string>:1>] [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/<string>:1] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def performJoin(self, inst): ids = inst._connection._SO_selectJoin( self.otherClass, self.joinColumn, > inst.id) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/joins.py:144] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _SO_selectJoin(self, soClass, column, value): return self.queryAll("SELECT %s FROM %s WHERE %s = %s" % (soClass.sqlmeta.idName, soClass.sqlmeta.table, column, > self.sqlrepr(value))) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:652] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def queryAll(self, s): > return self._runWithConnection(self._queryAll, s) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:327] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _runWithConnection(self, meth, *args): conn = self.getConnection() try: > val = meth(conn, *args) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:228] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _queryAll(self, conn, s): if self.debug: self.printDebug(conn, s, 'QueryAll') c = conn.cursor() > self._executeRetry(conn, c, s) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:320] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _executeRetry(self, conn, cursor, query): if self.debug: self.printDebug(conn, query, 'QueryR') E return cursor.execute(query) > OperationalError: no such column: person_id [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:306] - - - - - - - - - - - test_dynamicJoin: recorded stdout - - - - - - - - - - - 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/Query : DELETE FROM person 1/QueryR : DELETE FROM person 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/Query : DELETE FROM phone 1/QueryR : DELETE FROM phone 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('jane') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 1 1/QueryR : SELECT name_col FROM person WHERE id = 1 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('tim') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 2 1/QueryR : SELECT name_col FROM person WHERE id = 2 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('bob') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 3 1/QueryR : SELECT name_col FROM person WHERE id = 3 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('jake') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 4 1/QueryR : SELECT name_col FROM person WHERE id = 4 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('555-555-5555') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 1 1/QueryR : SELECT phone FROM phone WHERE id = 1 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('555-394-2930') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 2 1/QueryR : SELECT phone FROM phone WHERE id = 2 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('444-382-4854') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 3 1/QueryR : SELECT phone FROM phone WHERE id = 3 1/COMMIT : auto 1/Query : ALTER TABLE phone ADD COLUMN person_i_d_id INT 1/QueryR : ALTER TABLE phone ADD COLUMN person_i_d_id INT 1/COMMIT : auto 1/Select : SELECT phone.id, phone.phone, phone.person_i_d_id FROM phone WHERE 1 = 1 ORDER BY phone 1/QueryR : SELECT phone.id, phone.phone, phone.person_i_d_id FROM phone WHERE 1 = 1 ORDER BY phone 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'bob' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'bob' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/QueryAll: SELECT id FROM phone WHERE person_id = 2 1/QueryR : SELECT id FROM phone WHERE person_id = 2 1/COMMIT : auto ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-15 16:54 Message: Logged In: YES user_id=140558 Ok, here I go again. I've fixed a small bug: the name of the field was not porperly set when using Key(foreignKey... instead of ForeignKey. This fixes test_basic. And I think that there is nothing else to fix, I'm probably wrong, but I'll explain it hera. test_auto_old.py... FAIL test_auto.py... FAIL test_foreignKey.py... FAIL These tests fail because sqlite is failing when adding columns. In mysql it does not fail. I do not think it's this patch fault. And finally: test_SQLMultipleJoin.py... FAIL E assert str(hibrid.fightersAsSResult.sum('power')) == '23' > assert '23.0' == '23' + where '23.0' = str(23.0) + where 23.0 = <Race 3 name="'hibrid (human wi...'">.fightersAsSResult.sum('power') Again this is an error in the test. Please let me know if it can go in now :) If you can have a quick look at it better, it takes time to restart ths tests, I'd rather do it before I move on to another thing. Thanks Pau ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-14 10:05 Message: Logged In: YES user_id=140558 Oleg, I've posted to the list because I run the tests and pass. I'm sure I'm doing something wrong but I don't see what. I lost more than 3 hours yesterday just trying to run te tests :( I printed things in dbtest.py and say that TESTDB did not change anything. I chenged manually conftest.py because I ahd a message that yoiu need sqlite2 for memory databases, but still I'm not sure everything works becasue I pass al the tests. Can you help me, I want to close this patch soon and move to other improvements but this is being much more difficult than it should. Thanks a lot Pau ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-09 17:42 Message: Logged In: YES user_id=140558 I'm very busy but again will try to find some time to fix it. I'm using it every day without a glitch, even using the clause attributes like in the Complex example (new type of joins *toMany). I'll update it to latest SVN just in case this is the problem, I did it with that day's current. Please do not close it, I really intend to pass the tests, I'm already using it. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-09 17:11 Message: Logged In: YES user_id=4799 test_auto.py, for example fails: def test_dynamicJoin(self): col = KeyCol('personID', foreignKey='Person') Phone.sqlmeta.addColumn(col, changeSchema=True) join = MultipleJoin('Phone') Person.sqlmeta.addJoin(join) for phone in Phone.select('all'): if phone.phone.startswith('555'): phone.person = Person.selectBy(name='tim')[0] else: phone.person = Person.selectBy(name='bob')[0] l = [p.phone for p in Person.selectBy(name='tim')[0].phones] l.sort() E assert l == ['555-394-2930', '555-555-5555'] > assert [] == ['555-394-2930', '555-555-5555'] [sqlobject/tests/test_auto.py:61] ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-30 19:10 Message: Logged In: YES user_id=140558 I'll recheck it, it really passed all the tests applied to the latest svn. I tell you something tomorrow. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-30 19:07 Message: Logged In: YES user_id=140558 I'll recheck it, it really passed all the tests applied to the latest svn. I tell you something tomorrow. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-30 18:57 Message: Logged In: YES user_id=4799 test_auto.py, test_auto_old.py and test_basic.py failed. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-18 17:04 Message: Logged In: YES user_id=140558 This is the final patch against latest svn, it includes everything in one single patch. It passes the tests. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-18 14:17 Message: Logged In: YES user_id=140558 Ok, I have taken my time to understand pydist, test, etc, and here I am back with the working solution :) Now the resulting SQLobject passes all the tests. I attach an incremental patch so that you can see more clearly the changes done to fix the previous one. I've needed a new method in the Style class, instanceIDAttrToAttr, that is the complementary to the already known instanceAttrToIDAttr. If you need to transform back and forth field names, you need them both. I haven't tried to port it to the latest svn yet, this is against the same release than the first patch, but it should apply more or less clearly as this are very isolated areas in the code. When I do it I'll post it here. Sorry for the delay, it has not been easy for me to understand more deeply the code and, even less, to know how the tests work :) ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-03 13:18 Message: Logged In: YES user_id=140558 It fails because the test is not right, it still has the ID postfix hardcoded. My fault, I did no send a patch for tests. This is the piece that fails: # Select by usual way s = TestWorkKey.selectBy(composerID=c.id, title='Symphony No. 9') I have not looked at tests until now, but it looks like there should be tests for the different provides styles, in this case, if you accept the patch, at least a test for the LongStyle provided and for the current naming styles. I'll try to cook up something, but it can take a little time. Any guidelines will be appreciated (I've just read the docs ;) ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-03 12:23 Message: Logged In: YES user_id=4799 test_selectBy_foreignKey.py fails: def test1(): setupClass([TestComposerKey, TestWorkKey]) c = TestComposerKey(name='Mahler, Gustav') > w1 = TestWorkKey(composer=c, title='Symphony No. 9') [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/tests/test_selectBy_foreignKey.py:19] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def __init__(self, **kw): # The get() classmethod/constructor uses a magic keyword # argument when it wants an empty object, fetched from the # database. So we have nothing more to do in that case: if kw.has_key('_SO_fetch_no_create'): return post_funcs = [] self.sqlmeta.send(events.RowCreateSignal, kw, post_funcs) # Pass the connection object along if we were given one. if kw.has_key('connection'): self._connection = kw['connection'] self.sqlmeta._perConnection = True del kw['connection'] self._SO_writeLock = threading.Lock() if kw.has_key('id'): id = self.sqlmeta.idType(kw['id']) del kw['id'] else: id = None > self._create(id, **kw) [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/main.py:1210] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _create(self, id, **kw): self.sqlmeta._creating = True self._SO_createValues = {} self._SO_validatorState = SQLObjectState(self) # First we do a little fix-up on the keywords we were # passed: for column in self.sqlmeta.columnList: # Then we check if the column wasn't passed in, and # if not we try to get the default. if not kw.has_key(column.name) and not kw.has_key(column.foreignName): default = column.default # If we don't get it, it's an error: if default is NoDefault: E raise TypeError, "%s() did not get expected keyword argument %s" % (self.__class__.__name__, column.name) > TypeError: TestWorkKey() did not get expected keyword argument composerID [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/main.py:1231] - - - - - - - - - - - - - test1: recorded stdout - - - - - - - - - - - - - - 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/Query : CREATE TABLE test_composer_key ( id SERIAL PRIMARY KEY, name TEXT ) 1/QueryR : CREATE TABLE test_composer_key ( id SERIAL PRIMARY KEY, name TEXT ) 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/Query : CREATE TABLE test_work_key ( work_id SERIAL PRIMARY KEY, composer_id INT, title TEXT ) 1/QueryR : CREATE TABLE test_work_key ( work_id SERIAL PRIMARY KEY, composer_id INT, title TEXT ) 1/COMMIT : auto 1/Query : ALTER TABLE test_work_key ADD CONSTRAINT composer_id_exists FOREIGN KEY (composer_id) REFERENCES test_composer_key (id) 1/QueryR : ALTER TABLE test_work_key ADD CONSTRAINT composer_id_exists FOREIGN KEY (composer_id) REFERENCES test_composer_key (id) 1/COMMIT : auto 1/QueryIns: INSERT INTO test_composer_key (id, name) VALUES (1, 'Mahler, Gustav') 1/COMMIT : auto 1/QueryOne: SELECT name FROM test_composer_key WHERE id = 1 1/QueryR : SELECT name FROM test_composer_key WHERE id = 1 1/COMMIT : auto ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1353728&group_id=74338 |
|
From: SourceForge.net <no...@so...> - 2006-02-17 12:50:25
|
Patches item #1410527, was opened at 2006-01-20 08:42 Message generated for change (Comment added) made by linux4u You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1410527&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Closed Resolution: Accepted Priority: 5 Submitted By: Pau Aliagas (linux4u) Assigned to: Oleg Broytmann (phd) Summary: allow the use of foreign keys in selects (small jewel) Initial Comment: Many times you need to make a query that needs to filter using the foreign key. This should be trivial to do: just adding the foreign table or foreign table SHOULD work. But it does not. Better see the example: class handset_brand(SQLObject): brand = StringCol(alternateID = True, length = 50) handsets = SQLMultipleJoin('handset') class handset(SQLObject): handset_brand = ForeignKey('handset_brand') handset_made_in = ForeignKey('country') model = StringCol(alternateID = True, length = 25) class country(SQLObject): name StringCol(alternateID = True, length = 50) isocode StringCol(alternateID = True, length = 3) Query 1 ------- I want to query the handsets of one concrete brand. * solution 1 ---------- Now the best way to do it would be: handset_brands.get(4).handsets.filter(handset.q.model == "mymodel") but you NEED to define the MultipleJoin. * solution 2 ---------- You can use the dotq syntax: handset.select(handset.q.handset_brandID==4) For me the main problem is the you have to use the foreign key name defined in Style, so if you change the Style it would stop working. That's bad. * expected behaviour ------------------ I'd like to be able to do: handset.select(brandID = 4) or b = brand.get(4) handset.select(brand = b) One of both would be GREAT, but both would be AWSOME. This is the natural way of thinking. Query 2 ------- What if if want to filter using two foreign keys? For instance to query the handsets of one concrete brand made in one country. * solution 1 ---------- It would NOT work, you cannot query directly using both foreign tables. * solution 2 ---------- You can use the dotq syntax: handset.select(AND(handset.q.handset_brandID==4, handset.q.countryID==1)) Again, you have to use the foreign key name defined in Style. I try to avoid it, it feels like there SHOULD be a better way. * expected behaviour ------------------ I'd like to be able to do: handset.select(brandID = 4, countrID = 1) or b = brand.get(4) c = country.get(1) handset.select(brand = b, country = c) One of both, depending on the occasion, sometimes it would be better to use one way, sometimes the other one. In fact this is the way "INSERT" works!! Why not SELECT? The good news is that this small patch (3 lines) add this powerful features :) It really was trivial to do thanks to the well-designed code. Thanks very much for the hard work. As expected, it passes all the tests. ---------------------------------------------------------------------- >Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 13:50 Message: Logged In: YES user_id=140558 These are my versions: mysql-4.1.16-1.FC4.1 postgresql-8.0.7-1.FC4.1 python-psycopg-1.1.21-1.fc4 python-sqlite-1.1.6-1 sqlite-3.1.2-3 ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-10 15:54 Message: Logged In: YES user_id=4799 Applied at the revision 1587 to the trunk, 1588 to the 0.7-branch. I have slightly modified the patch and added a test. Please take a look. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-09 19:28 Message: Logged In: YES user_id=140558 I also want to do: s = TestWorkKey.selectBy(composer=c.id, title='Symphony No. 9') This way I can just use the more convenient value without changing the code. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-09 18:16 Message: Logged In: YES user_id=4799 I understand it. But I think s = TestWorkKey.selectBy(composer=c, title='Symphony No. 9') does what you want, doesn't it? ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-09 18:00 Message: Logged In: YES user_id=140558 What I want is to use the object or the field name seemlessly, so that I don't need to use the foreign key name that depends on the Stlye. I'd always use the object name like this. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-31 16:20 Message: Logged In: YES user_id=4799 This works in the trunk. Look at http://svn.colorstudy.com/SQLObject/trunk/sqlobject/tests/test_foreignKey.py: # Select by usual way s = TestWorkKey.selectBy(composerID=c.id, title='Symphony No. 9') assert s[0]==w1 # selectBy object s = TestWorkKey.selectBy(composer=c, title='Symphony No. 9') assert s[0]==w1 Isn't it what you want? ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-20 08:51 Message: Logged In: YES user_id=140558 There is a little mistake in the example: s/select/selectBy where it says: handset.select(brand = b, country = c) it should say: handset.selectBy(brand = b, country = c) This is how it really works (select always uses the dotq syntax). ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1410527&group_id=74338 |