Merge lp:~initos.com/openobject-server/trunk-bug-1314037 into lp:openobject-server

Proposed by Thomas Rehn
Status: Needs review
Proposed branch: lp:~initos.com/openobject-server/trunk-bug-1314037
Merge into: lp:openobject-server
Diff against target: 40 lines (+13/-2)
1 file modified
openerp/osv/expression.py (+13/-2)
To merge this branch: bzr merge lp:~initos.com/openobject-server/trunk-bug-1314037
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+217575@code.launchpad.net

Description of the change

Fixes the problem by using an alternative aliasing scheme based on hashes if the default method exceeds the limit.

To post a comment you must log in.

Unmerged revisions

5197. By Thomas Rehn

offer alternative scheme to generate table aliases

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openerp/osv/expression.py'
2--- openerp/osv/expression.py 2014-04-09 15:35:27 +0000
3+++ openerp/osv/expression.py 2014-04-29 10:51:49 +0000
4@@ -134,6 +134,7 @@
5
6 import logging
7 import traceback
8+import hashlib
9
10 import openerp.modules
11 from openerp.osv import fields
12@@ -341,7 +342,15 @@
13 return '%s' % alias, '%s' % _quote(alias)
14 for link in joined_tables:
15 alias += '__' + link[1]
16- assert len(alias) < 64, 'Table alias name %s is longer than the 64 characters size accepted by default in postgresql.' % alias
17+ # Use an alternate alias scheme if length exceeds the PostgreSQL limit
18+ # of 63 characters.
19+ if len(alias) >= 64:
20+ # We have to fit a 160 bit hash (= 40 characters) and one underscore
21+ # into a 63 character alias. The remaining space we can use to add
22+ # a human readable prefix.
23+ ALIAS_PREFIX_LENGTH = 63 - 40 - 1
24+ alias = "%s_%s" % (alias[:ALIAS_PREFIX_LENGTH],
25+ hashlib.sha1(alias).hexdigest())
26 return '%s' % alias, '%s as %s' % (_quote(joined_tables[-1][0]), _quote(alias))
27
28
29@@ -551,9 +560,11 @@
30 def get_join_conditions(self):
31 conditions = []
32 alias = self._models[0]._table
33+ links = []
34 for context in self.join_context:
35 previous_alias = alias
36- alias += '__' + context[4]
37+ links.append((context[1]._table, context[4]))
38+ alias, _ = generate_table_alias(self._models[0]._table, links)
39 conditions.append('"%s"."%s"="%s"."%s"' % (previous_alias, context[2], alias, context[3]))
40 return conditions
41