Cédric Krier pushed to branch branch/default at Tryton / Tryton


Commits:
d1475c50 by Cédric Krier at 2023-01-17T22:54:01+01:00
Test if count is callable before using it

ModelStorage.count has been added in 6.2 but there are existing Model that has
field with this name.

Closes #12016
- - - - -
dd995779 by Cédric Krier at 2023-01-17T23:01:08+01:00
Rename ModelStorage.count into ModelStorage.estimated_count

count is too common name for a standard method like #12016 reveals.
- - - - -


6 changed files:

- trytond/CHANGELOG
- trytond/doc/ref/models.rst
- trytond/trytond/model/fields/many2one.py
- trytond/trytond/model/fields/one2many.py
- trytond/trytond/model/modelsql.py
- trytond/trytond/model/modelstorage.py


Changes:

=====================================
trytond/CHANGELOG
=====================================
@@ -1,3 +1,4 @@
+* Rename ModelStorage.count into ModelStorage.estimated_count
 * Add border type to images
 * Lock table on transaction start
 * Use EXISTS for search on O2M with many records


=====================================
trytond/doc/ref/models.rst
=====================================
@@ -407,7 +407,7 @@
 
    It is used for the global search.
 
-.. classmethod:: ModelStorage.count()
+.. classmethod:: ModelStorage.estimated_count()
 
    Return an estimation of the number of records stored.
 


=====================================
trytond/trytond/model/fields/many2one.py
=====================================
@@ -259,7 +259,7 @@
         else:
             _, target_name = name.split('.', 1)
         target_domain = [(target_name,) + tuple(domain[1:])]
-        if Target.count() < _subquery_threshold:
+        if Target.estimated_count() < _subquery_threshold:
             query = Target.search(target_domain, order=[], query=True)
             return column.in_(query)
         else:


=====================================
trytond/trytond/model/fields/one2many.py
=====================================
@@ -337,7 +337,7 @@
             origin_where = origin.like(Model.__name__ + ',%')
             origin = origin_field.sql_id(origin, Target)
 
-        use_in = Target.count() < _subquery_threshold
+        use_in = Target.estimated_count() < _subquery_threshold
         if '.' not in name:
             if value is None:
                 if use_in:


=====================================
trytond/trytond/model/modelsql.py
=====================================
@@ -1647,7 +1647,7 @@
         main_table, _ = tables[None]
         if count:
             table = convert_from(None, tables)
-            if (limit is not None and limit < cls.count()) or offset:
+            if (limit is not None and limit < cls.estimated_count()) or offset:
                 select = table.select(
                     Literal(1), where=expression, limit=limit, offset=offset
                     ).select(Count(Literal('*')))
@@ -1878,7 +1878,7 @@
                     'You can not update fields: "%s", "%s"' %
                     (field.left, field.right))
 
-            if len(ids) < max(cls.count() / 4, 4):
+            if len(ids) < max(cls.estimated_count() / 4, 4):
                 for id_ in ids:
                     cls._update_tree(id_, field_name,
                         field.left, field.right)


=====================================
trytond/trytond/model/modelstorage.py
=====================================
@@ -609,7 +609,7 @@
         return process(domain)
 
     @classmethod
-    def count(cls):
+    def estimated_count(cls):
         "Returns the estimation of the number of records."
         count = cls._count_cache.get(cls.__name__)
         if count is None:



View it on Heptapod: 
https://foss.heptapod.net/tryton/tryton/-/compare/086626927118555c18f2c90519ead2de9de1303e...dd9957790a4743c4843911780a934faf36d756cf

-- 
View it on Heptapod: 
https://foss.heptapod.net/tryton/tryton/-/compare/086626927118555c18f2c90519ead2de9de1303e...dd9957790a4743c4843911780a934faf36d756cf
You're receiving this email because of your account on foss.heptapod.net.


Reply via email to