El dimecres 19 de juny de 2013 14:09:44 UTC+2, Cédric Krier va escriure:
> Hi,
>
> In the same idea as the changeset [1], I would like to propose this
> change for the write method:
>
> @classmethod
> def write(cls, records, values):
> …
>
> =>
>
> @classmethod
> def write(cls, records, values, *args):
> assert not len(args) % 2
> all_records = []
> actions = iter((records, values) + args)
> for records, values in zip(actions, actions):
> …
> all_records += records
>
> cls._validate(all_records)
>
I've been thinking in something in this line since the create with lists
implementation. The main issue I see is yet another important API change,
which we wanted to minimize.
I know it has some implementation issues but I also had another idea in
mind which maybe somebody has some ideas to improve and that it may be less
aggressive in terms of API changes. The idea is to implement deferred
validation in the same way a database implements deferred constraints.
Something like this:
with Transaction().set_deferred():
for record in records:
record.field = random.random()
record.save()
The checks would be executed on all modified records when exiting the with
statement.
Probably the main issue is that in case of a failure of the validation, it
may be harder to find where and when the value was set incorrectly, but
that's why that should be used in loops and places where the developer
knows beforehand that it can take advantage of deferring the validation.
One advantage is that it can defer validation in a loop of "create" or
"write" (for example, an import process which checks for the existance of a
record and creates it or updates it accordingly).
This has two advantages:
>
> - call validate for a larger set of records which will benefit of
> the prefetching
> - reduce the number of RPC calls
>
> PS: of course the write action in xxx2Many will follow.
>
> http://hg.tryton.org/trytond/rev/c7804c288ca3
> --
> Cédric Krier
>
> B2CK SPRL
> Rue de Rotterdam, 4
> 4000 Liège
> Belgium
> Tel: +32 472 54 46 59
> Email/Jabber: [email protected] <javascript:>
> Website: http://www.b2ck.com/
>