1818_logger = logging .getLogger (__name__ )
1919
2020
21- def read_spreadsheet_attachments (cr , like_pattern = "% " ):
21+ def read_spreadsheet_attachments (cr , like_pattern = "" ):
2222 yield from read_spreadsheet_initial_data (cr , like_pattern )
2323 yield from read_spreadsheet_snapshots (cr , like_pattern )
2424
2525
26- def read_spreadsheet_snapshots (cr , like_pattern = "% " ):
26+ def read_spreadsheet_snapshots (cr , like_pattern = "" ):
2727 cr .execute (
2828 """
2929 SELECT id, res_model, res_id, db_datas
3030 FROM ir_attachment
3131 WHERE res_model IN ('spreadsheet.dashboard', 'documents.document')
3232 AND res_field = 'spreadsheet_snapshot'
33- AND db_datas LIKE %s
33+ AND position(%s::bytea in db_datas) > 0
3434 """ ,
3535 [like_pattern ],
3636 )
37- # TODO LIKE probably doesn't work because the field is of type bytea
37+ # TODO rename 'like_pattern', it's not LIKE because LIKE doesn't work because the field is of type bytea
3838 for attachment_id , res_model , res_id , db_datas in cr .fetchall ():
3939 if db_datas :
4040 yield attachment_id , res_model , res_id , json .loads (db_datas .tobytes ())
4141
4242
43- def read_spreadsheet_initial_data (cr , like_pattern = "% " ):
43+ def read_spreadsheet_initial_data (cr , like_pattern = "" ):
4444 cr .execute (
4545 """
4646 SELECT doc.id AS document_id, a.id AS attachment_id, a.db_datas
4747 FROM documents_document doc
4848 LEFT JOIN ir_attachment a ON a.id = doc.attachment_id
4949 WHERE doc.handler='spreadsheet'
50- AND a. db_datas LIKE %s
50+ AND position(%s::bytea in db_datas) > 0
5151 """ ,
5252 [like_pattern ],
5353 )
@@ -63,7 +63,7 @@ def read_spreadsheet_initial_data(cr, like_pattern="%"):
6363 FROM ir_attachment
6464 WHERE res_model = 'spreadsheet.dashboard'
6565 AND res_field = %s
66- AND db_datas LIKE %s
66+ AND position(%s::bytea in db_datas) > 0
6767 """ ,
6868 [data_field , like_pattern ],
6969 )
@@ -74,7 +74,7 @@ def read_spreadsheet_initial_data(cr, like_pattern="%"):
7474def apply_in_all_spreadsheets (cr , like_pattern , callback ):
7575 _logger .info ("upgrading initial data and revisions" )
7676 # upgrade the initial data and all revisions based on it
77- for attachment_id , res_model , res_id , db_datas in read_spreadsheet_initial_data (cr ):
77+ for attachment_id , res_model , res_id , db_datas in read_spreadsheet_initial_data (cr , like_pattern ):
7878 revisions_data = []
7979 revisions_ids = []
8080 for revision_id , commands in get_revisions (cr , res_model , res_id , like_pattern ):
@@ -93,7 +93,7 @@ def apply_in_all_spreadsheets(cr, like_pattern, callback):
9393 )
9494 _logger .info ("upgrading snapshots" )
9595 # upgrade snapshots
96- for attachment_id , _res_model , _res_id , db_datas in read_spreadsheet_snapshots (cr ):
96+ for attachment_id , _res_model , _res_id , db_datas in read_spreadsheet_snapshots (cr , like_pattern ):
9797 data , revisions = callback (db_datas , [])
9898 write_attachment (cr , attachment_id , data )
9999
0 commit comments