Commit Graph
304 Commits
Author SHA1 Message Date
Cédric Krier 5c2782626b Use freezed context in order function
The hash method can no hash tuple containing unhashable element like a list.

issue8265
review265341002
2019-04-25 15:24:01 +02:00
Cédric Krier 12376f30e5 Order by target name and context hash
None can not be compared to a class so we always use strings to order before
grouping. Also dictionary can not be compared neither.

issue8265
review253351002
2019-04-24 23:40:46 +02:00
Cédric Krier 3e9784c8d7 Set context on record instantiated in Field.__set__ and read related
Field may have a context defined so when it instantiate a relational record,
the field should set this context like when the record is read from the
database in ModelStorage.__getattr__.
And when such field is read as related field, the context should also be set.

issue8225
review287171002
2019-04-04 19:06:09 +02:00
Cédric Krier bb0242faf8 Raise NotImplementedError when setting Function field without setter
issue7985
review265101002
2019-03-27 00:28:58 +01:00
Cédric Krier 10e31bc311 Add Model.__names__ to retrieve model and field names
issue8159
review72431002
2019-03-15 12:27:44 +01:00
Cédric Krier c255cfe785 Display ids and rule names on access error
issue8093
review60551002
2019-03-03 23:11:17 +01:00
Cédric Krier b34cac78d5 Allow to lock records for update
issue8012
review45901002
2019-01-30 09:45:59 +01:00
Cédric Krier 83bf159aef Check foreign key in last on database integrity error
The search is done on a new transaction so it can not find targets that were
created during the main transaction.
2018-12-29 23:28:40 +01:00
Cédric Krier 1738a4ec35 Add ir.message and use custom exceptions
issue3672
review35291002
2018-12-29 14:19:08 +01:00
Cédric Krier b387adc7bc Add check on ModelSQL for positive id
issue7867
review50631002
2018-12-22 00:01:41 +01:00
Cédric Krier d1bb790cb8 New API to read related fields
issue7888
review58431002
2018-12-21 23:41:56 +01:00
Sergi Almacellas Abellana fc5f906ce5 Do not initiate sql table when table_query is defined
issue7896
review64491002
2018-12-03 11:29:43 +01:00
Cédric Krier c7f5c54a83 Remove implicit fields names in ModelStorage.read
It is a bad practice to not explicit the fields to read. So we should not
support it.

issue7830
review54421002
2018-11-28 10:05:01 +01:00
Cédric Krier 1a3ee131fe Check read access on field in search domain
issue7766
review50591002
2018-11-12 17:18:06 +01:00
Cédric Krier 7a2ce7905a Add __table_handler__ to ModelSQL
issue7581
review48531002
2018-07-24 22:01:08 +02:00
Cédric Krier d2a461390a Remove support for Python 2.7
issue7497
review53261002
2018-06-26 19:11:19 +02:00
Cédric Krier 93526b9cd0 Check rule after indirect fields and modification
The rule may depend on indirect field written latter so it must be checked
after the storage of those fields.
On write, the rule must be checked before the modification but also after to
ensure users do not generate records that they can not modify after.

issue7403
review53301002
2018-06-24 16:54:46 +02:00
Cédric Krier d23d7c9ccb Do not call table_query for testing
Only the callable property of table_query is used to test if the ModelSQL uses
a table query or not.

issue5726
review47321002
2018-04-30 15:55:31 +02:00
Cédric Krier 60f167bcfe Add index method to order field set calls
issue7090
review46301002
2018-04-05 19:18:52 +02:00
Cédric Krier b15f3fb4c5 Do not append Exclude where clause if empty 2018-03-19 17:48:55 +01:00
Cédric Krier b3ca13748b Add Exclude constraint
issue1422
review44061002
2018-03-19 16:57:49 +01:00
Cédric Krier 62a90a603e Use unicode instead of str for DatabaseIntegrityError
The exception message could contain non-ASCII errors for which standard
__str__ may fail, but as the database should always be in UTF-8 we may except
that unicode will not fail.

issue6128
review43971002
2018-02-19 19:09:06 +01:00
Cédric Krier f911f48ed4 Delete translations only when model has translatable field
The call to Translation.delete_ids has a cost as it does search queries. So it
is better to not call it if we already know that there is nothing to delete.

issue7118
review37981003
2018-02-11 14:59:58 +01:00
Cédric Krier d813ac2090 Add limit to SQL queries consumed with a single fetchone call
This remove some load on the database server.
This is only needed for queries that may have more than one rows.

issue7040
review43001003
2018-01-09 18:31:00 +01:00
Sergi Almacellas Abellana 1aae453480 Don't use an sql query to delete target models if not ModelSQL
issue6525
review35431002
2017-06-30 09:46:21 +02:00
Cédric Krier a53883484e Update MPTT before the validation of created records
This prevent to fill the cache of the instances created with wrong values for
left/right fields. And it ensure that the validation code has valid MPTT
values.

issue6591
review34211002
2017-06-29 23:08:36 +02:00
Cédric Krier 4520afedd3 Convert into hash too long data name
Some back-ends have constraint on the length of data name, they usually
silently truncate them, but this can create collision. The solution is to hash
the name when it is too long.

issue4620
issue6494
review37381003
2017-05-12 12:00:44 +02:00
Sergi Almacellas Abellana 7ed3976d80 Use issubclass to test if foreign keys must be created
issue6491

review42321002
2017-05-08 12:00:37 +02:00
Cédric Krier 826f30219d Re-use method as default parameter of TableHandler add_column
There is no guarantee that the method will not raise a database error on the
first registration because it can rely on other tables being registered.
So the method must be called only when needed. This is when the table already
exists and has records. In this case other tables also already exist.

issue6409
2017-04-01 16:14:36 +02:00
Nicolas Évrard aa9c9cc9e7 Use sql type instead of field related argument in the column creation
issue6348
review26231002
2017-03-31 13:21:51 +02:00
Nicolas Évrard c3f69d1db7 Add NULLS ordering
issue5858
review27651002
2017-03-29 23:12:01 +02:00
Cédric Krier 2569f4dd52 Allow Many2One on ModelSQL to target ModelStorage
issue6237
review26081002
2017-02-11 19:08:52 +01:00
Cédric Krier 2351008095 Fill cache with selected columns in ModelSQL.read
This minimizes missing cache on the instances when computing Function field.

issue6209
review31981002
2017-02-02 11:57:18 +01:00
Cédric Krier 811cbb2ad4 Fix test to translate read field
The test was using the field name instead of the field instance.
It is better to keep the usual convention of using fname for name and field for
the instance.

issue6208
review33011002
2017-01-25 23:30:23 +01:00
Cédric Krier 24f386cd58 Backed out changeset bd4fb1ec9ebb
issue6128
2016-12-26 19:36:22 +01:00
Cédric Krier 037780d5ae Avoid to convert IntegrityError into string
Use message attribute instead of calling str because the message could be
non-ASCII encoded.

issue6128
review31831002
2016-12-26 18:56:07 +01:00
Cédric Krier bb27960228 Remove order constraint on register ModelSQL
We create the foreign table if needed before adding the foreign key constraint,
thus it is no more needed to order the registration of the ModelSQL.

issue5682
review32841002
2016-12-17 00:38:21 +01:00
Cédric Krier 21164f52b0 Use original transaction to check created/deleted records in __raise_integrity_error
The method is often called under a new transaction so the created/deleted
records properties are cleared which makes it raises the wrong message if the
foreign key was created during the same transaction.

issue6038
review29781002
2016-11-28 00:01:51 +01:00
Cédric Krier 26639ecd3f Format Many2One value before using it as id value in __raise_integrity_error
id is an Integer field which does not cast to int the values in the opposite of
Many2One which could receive an record instance.

issue6068
review31751003
2016-11-26 15:06:05 +01:00
Cédric Krier 6261fa486f Improve ModelStorage.search_count by using no order and COUNT(*)
issue5877
review27651003
2016-09-27 12:18:16 +02:00
Cédric Krier 02fa7b240a Allow to call ModelSQL.__insert_history
Rename __insert_history into _insert_history to be able to call it
when records are manipulated via SQL queries.

issue5819
review32471002
2016-09-06 09:08:50 +02:00
Cédric Krier ae51da69a1 Consume only requested fields from Fields.get method
Badly written getter could return more values than requested. This can corrupt
the browse cache as it only filter on requested fields.

issue5805
review21221002
2016-08-25 19:14:13 +02:00
Cédric Krier c4c6e6ed54 Do not set NOT NULL on any Binary fields
Even if the data is stored in the database, the column is filled only after the
initial insert by the set method.
2016-07-29 12:17:04 +02:00
Cédric Krier 7ca7f4c6f0 Allow to store Binary field in filestore
Two options are added on Binary field to define the column to use to store the
filestore id and the prefix to use.
Those options are used for Attachment and are configurable with conservative
default values.

issue5692
review25471003
2016-07-29 10:51:53 +02:00
Cédric Krier 46ff36af7b Use str to test exception instead of unicode in integrity error
issue5446
review19161003
2016-04-01 10:29:51 +02:00
Cédric Krier 792d623c7b Improve threshold between rebuild and update MPTT
Indeed we should count the number of nodes updated instead of the number of
queries.

rebuild: 1 write and 1 select on each node
update: (1 write + 3 select + 2 write on average ½ all nodes + 1 write on child
of id) on each ids

So the threshold is:

2 * count < (4 + 2 * count / 2 + 1 * x) * len(ids)
2 * count < (4 + count + x) * len(ids)

which can be approximated to

2 * count < count * len(ids)
2 < len(ids)

issue5399
review20861002
2016-03-21 23:43:22 +01:00
Cédric Krier 23c45fc511 Group records when calling set method for field with the same value
We need to loop to compare the values instead of using a dictionary because the
values are not necessary hashable. But it is still an improvement compared to
calling the set method for each record.

issue5398
review19111002
2016-03-19 12:07:27 +01:00
Cédric Krier 1380d60c45 Cache default values in ModelSQL.create
default values should be constant during the create transaction so we could
cache the result and avoid query it for each created record.

issue5397
review16121002
2016-03-19 12:04:35 +01:00
Cédric Krier 9dfb717088 Always use __name__ instead of _get_name to raise access_error
Other similar exception use __name__
2016-03-16 12:48:15 +01:00
Nicolas Évrard 2fef479575 Follow PEP-0249 for Transaction and backends
issue4949
review19781002
2016-03-03 21:51:57 +01:00