trytond: Migration to python-sql

143 views
Skip to first unread message

Code Review - New issues: ced

unread,
Jul 26, 2013, 8:52:12 AM7/26/13
to tryto...@googlegroups.com
TODO:

- test mysql
- update doc
- migrate modules

URL: http://codereview.tryton.org/1001002/

Cédric Krier

unread,
Jul 27, 2013, 5:17:06 PM7/27/13
to tryto...@googlegroups.com
On 26/07/13 12:52 -0000, Code Review - New issues: ced wrote:
> URL: http://codereview.tryton.org/1001002/

I would like to share some changes I have done in this patch with the
refactoring:

- Field.order_field:

I remove it and replace by a generic function (similar to
default value) with this form:

@classmethod
def order_<field name>(cls, tables):


where tables is a dict of dict containing the joins somthing
like this:

{
None: (invoice, None),
'party': {
None: (party, <join_on sql expression>),
'addresses': {
None: (address, <on>),
},
},
'lines': {
None: (invoice_lines, <on>),
},
}

and the method should return a sql expression (or a list) on
which to order.

this is a more powerful feature then the previous one as it
allows to add tables to join on for the ordering.

- Function.searcher:

The searcher method can return a full domain (instead of a
simple 'AND').

- Field.convert_domain(self, domain, tables, Model):

The convertion of the simple domain clause is managed by the
field. This will allow to define new OPERATORS for specific
fields. The method can return any sql expression and also
modify the tables to add new join's.
For now, the nested joins are still using subqueries but a
future optimisation could convert them into real join's.

- Field.sql_format:

Same as above but for formating the value

- Field.sql_type:

Return the namedtuple('SQLType', 'base type') which defines the
SQL type to use for creation and casting.

- backend:

It is now dynamic so we don't have to worry about early import.
This will also allow to have external lib (or move out MySQL) to
implement new DB support.

- None vs False:

I fixed some more misuse of False and we are more strict on this
topic.

Comments are welcome.

--
Cédric Krier

B2CK SPRL
Rue de Rotterdam, 4
4000 Liège
Belgium
Tel: +32 472 54 46 59
Email/Jabber: cedric...@b2ck.com
Website: http://www.b2ck.com/

Sergi Almacellas Abellana

unread,
Jul 29, 2013, 6:44:24 AM7/29/13
to tryto...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Al 27/07/13 23:17, En/na Cédric Krier ha escrit:
> On 26/07/13 12:52 -0000, Code Review - New issues: ced wrote:
>> URL: http://codereview.tryton.org/1001002/
>
> I would like to share some changes I have done in this patch with
> the refactoring:
>
> - Field.order_field:
>
> I remove it and replace by a generic function (similar to default
> value) with this form:
>
> @classmethod def order_<field name>(cls, tables): …
>
> where tables is a dict of dict containing the joins somthing like
> this:
>
> { None: (invoice, None), 'party': { None: (party, <join_on sql
> expression>), 'addresses': { None: (address, <on>), }, }, 'lines':
> { None: (invoice_lines, <on>), }, }
>
> and the method should return a sql expression (or a list) on which
> to order.
>
> this is a more powerful feature then the previous one as it allows
> to add tables to join on for the ordering.

This will help to solve isue3306, and therefore issue1085. So for me
its worth. Nothing to say about the desing, makes full sense.



- --
Sergi Almacellas Abellana
www.koolpi.com
Twitter: @pokoli_srk

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBAgAGBQJR9keFAAoJEGRfwiQCVal5eO8IAI0aew5gRwN6zAUSn5rqvxY2
ZE5EYHsuIhsreIiZRIfETJpSiMrcPpsLqZKpMmj9LGJQLa35hUyGDcATZNzhKySS
2XTIQ+c9senb8V4hpuGVsAPzjBv+r3RFs9+THsXxOqWqPVhynY2Yoh7jOl3ly7eh
t7XVplWKF4FevBDomRff+TgZQqXgYA9gxiPCb+HGQ8KR1LVb0skI1SuesJD36vAz
qWrRbXvo+G2PX7i2T19iZHIDLvk/7J1DZTbajqZz+n1tz/b0fcUPoQjLT7kIuUOg
kFLeb233YhSWrgBcGKsD6xoMBzs8CUHgB/GU6kDyLt4F7+AXzkIQYAqDAHY2FeQ=
=KNWW
-----END PGP SIGNATURE-----

Cédric Krier

unread,
Aug 8, 2013, 6:06:34 AM8/8/13
to tryto...@googlegroups.com
On 26/07/13 12:52 -0000, Code Review - New issues: ced wrote:
> TODO:
>
> - test mysql
>
> URL: http://codereview.tryton.org/1001002/

The patch is ready for testing. All the unittest pass and the simple
sale-invoice-purchase-shipment workflow works.
As our unittest doesn't yet fully cover the application, I'm calling for
testers.

To test, you need to apply also those patches:

- http://codereview.tryton.org/1014002/
- http://codereview.tryton.org/1012002/

and to install latest python-sql: https://code.google.com/p/python-sql/

Please try to test the unsual workflow or features because standard is
already well tested.

I still have to test in MySQL backend (but it is less important :-))

Some stats:

192 files changes, 4533 insertions(+), 4860 deletions(-)

Thanks,

Cédric Krier

unread,
Aug 10, 2013, 8:43:40 PM8/10/13
to tryto...@googlegroups.com
On 08/08/13 12:06 +0200, Cédric Krier wrote:
> I still have to test in MySQL backend (but it is less important :-))

Done.

Sergi Almacellas Abellana

unread,
Aug 27, 2013, 1:38:54 PM8/27/13
to tryto...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Al 08/08/13 12:06, En/na Cédric Krier ha escrit:
> On 26/07/13 12:52 -0000, Code Review - New issues: ced wrote:
>>> TODO:
>>>
>>> - test mysql
>>>
>>> URL: http://codereview.tryton.org/1001002/
> The patch is ready for testing. All the unittest pass and the
> simple sale-invoice-purchase-shipment workflow works. As our
> unittest doesn't yet fully cover the application, I'm calling for
> testers.

As hg review doesn't work with nested repositories the patch must
split by hand. If anyone is interesed on the invididual files for
modules I can share it :)



- --
Sergi Almacellas Abellana
www.koolpi.com
Twitter: @pokoli_srk

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBAgAGBQJSHOQqAAoJEGRfwiQCVal5d3oH/3nDVivrUFSXvhuHdKniSPx2
sUUc6tWnZ3XhIGevjuEmreawV+VFq9hUfTPj6YeKIN0Oc587cpjTVVGaqia4nQD/
KA71K1MNnhy6EmBSKFALkalaZAQYLWydCLtQmYrH1o3v4fAvgfAUk1nHbdgvRMXZ
YN/pLEiVZ4vTbcZJ4JsfYOOdL9Ch3bVdriq2dlG9WqIuw+v1Ur4jPD0fBACvabft
J9K2FczHHrSGyzcU1peCw6habky4bwZiJhawbS39+xqmHP9pBpXF4oIdSVbFSN1a
IEeXha7OPxVNk0vEIFV6Bb+8aIeGK6P2LTQ063Wnu/eeWPNDggkBpxNx56o/tbI=
=aY3W
-----END PGP SIGNATURE-----

Nicolas Évrard

unread,
Aug 28, 2013, 1:12:30 AM8/28/13
to tryto...@googlegroups.com
* Sergi Almacellas Abellana [2013-08-27 19:38 +0200]:
>Al 08/08/13 12:06, En/na Cédric Krier ha escrit:
>> On 26/07/13 12:52 -0000, Code Review - New issues: ced wrote:
>>>> TODO:
>>>>
>>>> - test mysql
>>>>
>>>> URL: http://codereview.tryton.org/1001002/
>> The patch is ready for testing. All the unittest pass and the
>> simple sale-invoice-purchase-shipment workflow works. As our
>> unittest doesn't yet fully cover the application, I'm calling for
>> testers.
>
>As hg review doesn't work with nested repositories the patch must
>split by hand. If anyone is interesed on the invididual files for
>modules I can share it :)

In theory hgreview says that it has fetched a patch somewhere in /tmp,
you can use this file directly.

One day, I'll use this file to apply the patch using the patch command.

--
Nicolas Évrard

B2CK SPRL
4, rue de Rotterdam
4000 Liège
Belgium
Tel: +32 472 54 46 59
E-mail/Jabber: nicolas...@b2ck.com
Website: http://www.b2ck.com/
signature.asc

Guillem Barba Domingo

unread,
Aug 28, 2013, 2:47:50 AM8/28/13
to tryto...@googlegroups.com


El 28/08/2013 7:12, "Nicolas Évrard" <nicolas...@b2ck.com> va escriure:


>
> * Sergi Almacellas Abellana  [2013-08-27 19:38 +0200]:
>>

>> As hg review doesn't work with nested repositories the patch must
>> split by hand. If anyone is interesed on the invididual files for
>> modules I can share it :)
>
>
> In theory hgreview says that it has fetched a patch somewhere in /tmp,
> you can use this file directly.
>
> One day, I'll use this file to apply the patch using the patch command.

Yes, it works. I used this trick several times.

$ hg review --fetch -n -i XXX
Error... /tmp/YYY
$ patch -p1 < /tmp/YYY

To push, it works with "-n" option without problems.

Sergi Almacellas Abellana

unread,
Aug 29, 2013, 11:25:40 AM8/29/13
to tryto...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Al 28/08/13 08:47, En/na Guillem Barba Domingo ha escrit:
>
> El 28/08/2013 7:12, "Nicolas Évrard" <nicolas...@b2ck.com
> <mailto:nicolas...@b2ck.com>> va escriure:
>>
>> * Sergi Almacellas Abellana [2013-08-27 19:38 +0200]:
>>>
>>> As hg review doesn't work with nested repositories the patch
>>> must split by hand. If anyone is interesed on the invididual
>>> files for modules I can share it :)
>>
>>
>> In theory hgreview says that it has fetched a patch somewhere in
>> /tmp, you can use this file directly.
>>
>> One day, I'll use this file to apply the patch using the patch
>> command.
>
> Yes, it works. I used this trick several times.
>
> $ hg review --fetch -n -i XXX Error... /tmp/YYY $ patch -p1 <
> /tmp/YYY
>

Thanks for the tip, it worked perfectly :)

Patch doesn't apply on tip, but this is another thing.

I managed to apply it with revesion 3121 of trytond, revision 219 of
timesheet and revision 618 of account_invoice. Other repors applied
withous problems.

After appling it i got the following errors after creating a new database:

Traceback (most recent call last):
File
"/home/pokoli/tryton/python-sql/trytond/trytond/protocols/dispatcher.py",
line 243, in create
pool.init(update=True, lang=[lang])
File "/home/pokoli/tryton/python-sql/trytond/trytond/pool.py", line
151, in init
lang=lang)
File
"/home/pokoli/tryton/python-sql/trytond/trytond/modules/__init__.py",
line 398, in load_modules
load_module_graph(graph, pool, lang)
File
"/home/pokoli/tryton/python-sql/trytond/trytond/modules/__init__.py",
line 261, in load_module_graph
Translation.translation_import(lang2, module, filename)
File
"/home/pokoli/tryton/python-sql/trytond/trytond/ir/translation.py",
line 718, in translation_import
('name', 'DESC'),
File
"/home/pokoli/tryton/python-sql/trytond/trytond/model/modelsql.py",
line 887, in search
forder = field.convert_order(fname, tables, cls)
File
"/home/pokoli/tryton/python-sql/trytond/trytond/model/fields/selection.py",
line 51, in convert_order
selections = Model.fields_get([name])[name]['selection']
File
"/home/pokoli/tryton/python-sql/trytond/trytond/model/model.py", line
214, in fields_get
accesses = FieldAccess.get_access([cls.__name__])[cls.__name__]
File "/home/pokoli/tryton/python-sql/trytond/trytond/ir/model.py",
line 607, in get_access
UserGroup = pool.get('res.user-res.group')
File "/home/pokoli/tryton/python-sql/trytond/trytond/pool.py", line
168, in get
return self._pool[self.database_name][type][name]
KeyError: 'res.user-res.group'


The only strange thing is that I am creating the database in a Catalan.

My bacquend id PostgreSQL.

Any tips?


- --
Sergi Almacellas Abellana
www.koolpi.com
Twitter: @pokoli_srk

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBAgAGBQJSH2fvAAoJEGRfwiQCVal57zEH/jQrmyDdLf7aD35U+1BBHrcb
+vBElxJFVxsq9IQ2NNQ/WkU9N1l2jycI8ghMpD/u2bj7mLD/VECOb44bTQZqUQlf
lJvX8QOZGsUJa29QBzo4BtQtCFEm4p5V1IkZvCz/vtvjtwzUPkNnWg2rKhfVGD9f
Coup15nL3EO98GWWNatkqrs2RlEq8Mjqno/V2QUVv2q8rhEHP7ucgO78Dw0SIMRh
D8qDZCAHRRDwEAG75wXj60NXFDbqLRhFGSrmUCB0sVx+zjyUu02Mf1YwQr96Q3sf
BBr/7d8s8W8VG8dRGlT4M3Od7lv9Aa00GYmTW2b46hBZViaCL0DHTbBPAGtWc2Y=
=Xtd+
-----END PGP SIGNATURE-----

Cédric Krier

unread,
Aug 29, 2013, 4:08:35 PM8/29/13
to tryto...@googlegroups.com
Yes it is linked to the fact that you create a DB with a translatable
language.
But I think the issue is just reveal but python-sql, the get_access
should return always True for root user.
I will submit a patch on trunk for that.

--
Cédric Krier

B2CK SPRL
Rue de Rotterdam, 4
4000 Liège
Belgium
Tel: +32 472 54 46 59

Sergi Almacellas Abellana

unread,
Aug 29, 2013, 4:58:19 PM8/29/13
to tryto...@googlegroups.com


"Cédric Krier" <cedric...@b2ck.com> ha escrit:
So maybe adding a test that installs a database in a translatable language should help to prevent those issues.

I can work on it if you can provide some guide.

>But I think the issue is just reveal but python-sql, the get_access
>should return always True for root user.

Sorry but didn't understand you here.

>I will submit a patch on trunk for that.

Trunk of tryton or trunk of python-sql?

I want to test the patch when done, so would be great if you can inform me :)

--
Enviado desde mi teléfono Android con K-9 Mail. Disculpa mi brevedad

Cédric Krier

unread,
Aug 29, 2013, 7:06:16 PM8/29/13
to tryto...@googlegroups.com
On 29/08/13 22:58 +0200, Sergi Almacellas Abellana wrote:
> >Yes it is linked to the fact that you create a DB with a translatable
> >language.
>
> So maybe adding a test that installs a database in a translatable language should help to prevent those issues.

Maybe but it will be a very slow test and I think it should install all
languages.

> I can work on it if you can provide some guide.
>
> >But I think the issue is just reveal but python-sql, the get_access
> >should return always True for root user.
>
> Sorry but didn't understand you here.

Oops should be:

But I think the issue is just reveal by python-sql, the get_access
should return always True for root user

> >I will submit a patch on trunk for that.
>
> Trunk of tryton or trunk of python-sql?
>
> I want to test the patch when done, so would be great if you can inform me :)

It is here: http://codereview.tryton.org/1049002/

Sergi Almacellas Abellana

unread,
Aug 30, 2013, 6:27:06 AM8/30/13
to tryto...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Al 30/08/13 01:06, En/na Cédric Krier ha escrit:
> On 29/08/13 22:58 +0200, Sergi Almacellas Abellana wrote:
>>> Yes it is linked to the fact that you create a DB with a
>>> translatable language.
>>
>> So maybe adding a test that installs a database in a translatable
>> language should help to prevent those issues.
>
> Maybe but it will be a very slow test and I think it should install
> all languages.
>
>> I can work on it if you can provide some guide.
>>
>>> But I think the issue is just reveal but python-sql, the
>>> get_access should return always True for root user.
>>
>> Sorry but didn't understand you here.
>
> Oops should be:
>
> But I think the issue is just reveal by python-sql, the get_access
> should return always True for root user
>
>>> I will submit a patch on trunk for that.
>>
>> Trunk of tryton or trunk of python-sql?
>>
>> I want to test the patch when done, so would be great if you can
>> inform me :)
>
> It is here: http://codereview.tryton.org/1049002/
>

That solved the problem for me.

I will report further issues on the codereview.



- --
Sergi Almacellas Abellana
www.koolpi.com
Twitter: @pokoli_srk

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEbBAEBAgAGBQJSIHN3AAoJEGRfwiQCVal5cJwH+IidhBUPW96Ev5wrngouyVJr
LiGSyCr1Pz11FGBJs2++zoN/6BKgMtiauLVBpqmRGpjgr2TuG1trE4vZMAKESE7d
CssacX1NV53O+IQR8+ucPqwiDG1CY/vHhQLsIaGdHrUZCATFGhyBvpX8YPsGjvKq
OV8Ur0z3eS358LcKRFlLL6ZSFxD/ua28dLJ6HB3NzI9qKpTUSc5njr6rtkAA+ifa
DHPgiHwUVLClzc+4/7eIUaNRdhFP3U/vf/QvKs6ecT/S5sLSCYP1/UsCVvv0/pqP
8nlg1zqD4JeyTQIgYKsEtmwkslJUvpmQHY6rN19jGDzWEvKa7HC72MuOm2b+NA==
=keXy
-----END PGP SIGNATURE-----
Reply all
Reply to author
Forward
0 new messages