Skip to content

[9.0][FIX] base_multi_image - New storage backend 'Filestore'#468

Merged
dreispt merged 5 commits intoOCA:9.0from
osiell:9.0-base_multi_image_binary_attachment
Jul 4, 2016
Merged

[9.0][FIX] base_multi_image - New storage backend 'Filestore'#468
dreispt merged 5 commits intoOCA:9.0from
osiell:9.0-base_multi_image_binary_attachment

Conversation

@sebalix
Copy link
Copy Markdown
Contributor

@sebalix sebalix commented Jun 29, 2016

New storage backend Filestore to link an existing attachment record + Fix the pre_init_hook_for_submodules() function to extract the images from the ir_attachment table for binary fields initialized with the attachment=True parameter.

Required to fix OCA/product-attribute#161

I'm not quite satisfied with the pre_init_hook function, it works but it is not really elegant and error prone. Any advices?

cc @yajo @atchuthan @pedrobaeza

@sebalix sebalix changed the title [FIX] base_multi_image - New storage backend 'Filestore' [9.0][FIX] base_multi_image - New storage backend 'Filestore' Jun 29, 2016
…xisting attachment record + Fix the 'pre_init_hook_for_submodules()' hook to extract the images from the ir_attachment table for binary fields initialized with the 'attachment=True' parameter
@sebalix sebalix force-pushed the 9.0-base_multi_image_binary_attachment branch from e2de984 to 16e7412 Compare June 29, 2016 10:13
@sebalix
Copy link
Copy Markdown
Contributor Author

sebalix commented Jun 29, 2016

Ready for reviews.

@api.constrains('storage', 'attachment_id')
def _check_store(self):
if self.storage == 'filestore' and not self.attachment_id:
raise exceptions.ValidationError(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

base_multi_image/models/image.py:195: [C8107(translation-required), Image._check_store] String parameter of raise "ValidationError" requires translation. Use _('You must provide an attachment for the image.')

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@moylop260
Copy link
Copy Markdown
Contributor

👍

@sebalix
Copy link
Copy Markdown
Contributor Author

sebalix commented Jun 30, 2016

I would like to discuss about what we should do about these Binary(attachment=True) fields. There is several solutions.

The pros of the implementation proposed in this PR:

  • allow to select the same image (attachment) several times for different galleries without any additional space
  • small PostgreSQL dumps as the images are stored in the filestore
  • no data loss on migrated fields when uninstalling the module

Cons:

  • the UX with this attachment_id field isn't very convenient

Another method is to add a new binary field file_db_store_attachment with attachment=True, linked to a new backend db_attachment. This way we can manage these two kind of storage: binary in database (db) and binary as attachment (db_attachment). Then the pre_init_hook function could migrate Binary(attachment=True) fields (e.g. in product.template https://github.com/odoo/odoo/blob/9.0/addons/product/product.py#L538) by updating the relevant data in the ir_attachment table (res_model, res_id and res_field).

Pros:

  • small PostgreSQL dumps as the images are stored in the filestore
  • good UX, a normal binary field on the form as it is now

Cons:

  • bad UX, choose between Database and Database/Attachment is unclear (maybe add the possibility to enable/disable the different storage backends for integrators, another problem for another PR)
  • unable to select the same image several times, each use needs to be stored
  • uninstalling the module will not recover the migrated ir.attachment records

@lasley
Copy link
Copy Markdown
Contributor

lasley commented Jun 30, 2016

IMO the implementation in this PR is great. (code review 👍 btw)

I would also say that the migration of image records into an unrecoverable table could be a big red flag in terms of using this module. As a sys admin, I naturally shy away from something that migrates my data without a way to walk it back.

@atchuthan
Copy link
Copy Markdown
Member

code review 👍

@dreispt dreispt merged commit 30f2075 into OCA:9.0 Jul 4, 2016
@sebalix sebalix deleted the 9.0-base_multi_image_binary_attachment branch July 13, 2016 22:40
SiesslPhillip pushed a commit to grueneerde/OCA-server-tools that referenced this pull request Nov 20, 2024
Syncing from upstream OCA/server-tools (12.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants