Commit d1475c50 authored by Cédric Krier's avatar Cédric Krier
Browse files

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
parent 086626927118
......@@ -259,7 +259,7 @@
else:
_, target_name = name.split('.', 1)
target_domain = [(target_name,) + tuple(domain[1:])]
if Target.count() < _subquery_threshold:
if callable(Target.count) and Target.count() < _subquery_threshold:
query = Target.search(target_domain, order=[], query=True)
return column.in_(query)
else:
......
......@@ -337,7 +337,8 @@
origin_where = origin.like(Model.__name__ + ',%')
origin = origin_field.sql_id(origin, Target)
use_in = Target.count() < _subquery_threshold
use_in = (
callable(Target.count) and Target.count() < _subquery_threshold)
if '.' not in name:
if value is None:
if use_in:
......
......@@ -1647,7 +1647,9 @@
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 callable(cls.count)
and limit < cls.count()) or offset:
select = table.select(
Literal(1), where=expression, limit=limit, offset=offset
).select(Count(Literal('*')))
......@@ -1878,7 +1880,7 @@
'You can not update fields: "%s", "%s"' %
(field.left, field.right))
if len(ids) < max(cls.count() / 4, 4):
if callable(cls.count) and len(ids) < max(cls.count() / 4, 4):
for id_ in ids:
cls._update_tree(id_, field_name,
field.left, field.right)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment