OCA / website-themes

Website themes for Odoo
GNU Affero General Public License v3.0
28 stars 104 forks source link

website_theme_flexible: Internal Server Error: not enough arguments for format string when having activated the developer mode with assets #2

Open treviser opened 6 years ago

treviser commented 6 years ago

Module: Website Theme Flexible website-theme-flexible Environment: Ubuntu 16.04 LTS, Odoo 11.0 CE Vers. 2018-03-21

Traceback:

not enough arguments for format string
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/odoo/tools/cache.py", line 84, in lookup
    r = d[key]
  File "/usr/lib/python3/dist-packages/odoo/tools/func.py", line 68, in wrapper
    return func(self, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/odoo/tools/lru.py", line 44, in __getitem__
    a = self.d[obj].me
KeyError: ('ir.qweb', <function IrQWeb._get_asset at 0x7f40c9614510>, 'web.assets_frontend', 'en_US', True, False, 'assets', False, (1,))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/odoo/addons/base/ir/ir_qweb/qweb.py", line 341, in _compiled_fn
    return compiled(self, append, new, options, log)
  File "<template>", line 1, in template_website_layout_1436
  File "<template>", line 2, in body_call_content_1435
  File "<template>", line 19, in set_1401
  File "/usr/lib/python3/dist-packages/odoo/addons/website/models/ir_qweb.py", line 30, in _get_asset
    return super(QWeb, self)._get_asset(xmlid, options, css, js, debug, async, values)
  File "<decorator-gen-37>", line 2, in _get_asset
  File "/usr/lib/python3/dist-packages/odoo/tools/cache.py", line 89, in lookup
    value = d[key] = self.method(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/odoo/addons/base/ir/ir_qweb/ir_qweb.py", line 197, in _get_asset
    return asset.to_html(css=css, js=js, debug=debug, async=async, url_for=(values or {}).get('url_for', lambda url: url))
  File "/usr/lib/python3/dist-packages/odoo/addons/base/ir/ir_qweb/assetsbundle.py", line 109, in to_html
    is_css_preprocessed, old_attachments = self.is_css_preprocessed()
  File "/usr/lib/python3/dist-packages/odoo/addons/base/ir/ir_qweb/assetsbundle.py", line 315, in is_css_preprocessed
    assets = dict((asset.html_url, asset) for asset in self.stylesheets if isinstance(asset, atype))
  File "/usr/lib/python3/dist-packages/odoo/addons/base/ir/ir_qweb/assetsbundle.py", line 315, in <genexpr>
    assets = dict((asset.html_url, asset) for asset in self.stylesheets if isinstance(asset, atype))
  File "/usr/lib/python3/dist-packages/odoo/addons/base/ir/ir_qweb/assetsbundle.py", line 460, in html_url
    return self.html_url_format % self.html_url_args
TypeError: not enough arguments for format string

Error to render compiling AST
TypeError: not enough arguments for format string
Template: website.layout
Path: /templates/t/t/t[5]/t[7]
Node: <t t-call-assets="web.assets_frontend" t-js="false"/>
pedrobaeza commented 6 years ago

But due to what module?

treviser commented 6 years ago

Sorry, issue updated (did not mention it, because it is the only module so far in this repo branch 11.0)

pedrobaeza commented 6 years ago

@tarteo can you check?

treviser commented 6 years ago

The developer mode with assets remains unusable even after proper deinstallation of the app and subsequent database update including Odoo restart.

njeudy commented 6 years ago

@pedrobaeza @tarteo I trace the bug, when installing flexible_theme module and having debug=assets on website you will have this error.

Probleme was odoo does not generate correctly URL for those file:

- templates/options/anchor.xml
- templates/options/colors.xml
- templates/options/fonts.xml
- template/options/layout.xml
- template/options/menu.xml

I don't know if we could inherit less template like this with inline less .. it work but traceback in debug=assets mode ...

here is the complete traceback

Traceback (most recent call last):
  File "/opt/odoo/custom/src/odoo/odoo/tools/cache.py", line 84, in lookup
    r = d[key]
  File "/opt/odoo/custom/src/odoo/odoo/tools/func.py", line 68, in wrapper
    return func(self, *args, **kwargs)
  File "/opt/odoo/custom/src/odoo/odoo/tools/lru.py", line 44, in __getitem__
    a = self.d[obj].me
KeyError: ('ir.qweb', <function IrQWeb._get_asset at 0x7fd66096f378>, 'web.assets_frontend', 'en_US', True, False, 'assets', False, (1,))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/odoo/custom/src/odoo/odoo/addons/base/ir/ir_qweb/qweb.py", line 341, in _compiled_fn
    return compiled(self, append, new, options, log)
  File "<template>", line 1, in template_website_layout_505
  File "<template>", line 2, in body_call_content_504
  File "<template>", line 23, in set_485
  File "/opt/odoo/auto/addons/website/models/ir_qweb.py", line 34, in _get_asset
    return super(QWeb, self)._get_asset(xmlid, options, css, js, debug, async, values)
  File "<decorator-gen-37>", line 2, in _get_asset
  File "/opt/odoo/custom/src/odoo/odoo/tools/cache.py", line 89, in lookup
    value = d[key] = self.method(*args, **kwargs)
  File "/opt/odoo/custom/src/odoo/odoo/addons/base/ir/ir_qweb/ir_qweb.py", line 197, in _get_asset
    return asset.to_html(css=css, js=js, debug=debug, async=async, url_for=(values or {}).get('url_for', lambda url: url))
  File "/opt/odoo/custom/src/odoo/odoo/addons/base/ir/ir_qweb/assetsbundle.py", line 109, in to_html
    is_css_preprocessed, old_attachments = self.is_css_preprocessed()
  File "/opt/odoo/custom/src/odoo/odoo/addons/base/ir/ir_qweb/assetsbundle.py", line 315, in is_css_preprocessed
    assets = dict((asset.html_url, asset) for asset in self.stylesheets if isinstance(asset, atype))
  File "/opt/odoo/custom/src/odoo/odoo/addons/base/ir/ir_qweb/assetsbundle.py", line 315, in <genexpr>
    assets = dict((asset.html_url, asset) for asset in self.stylesheets if isinstance(asset, atype))
  File "/opt/odoo/custom/src/odoo/odoo/addons/base/ir/ir_qweb/assetsbundle.py", line 462, in html_url
    return self.html_url_format % self.html_url_args
TypeError: not enough arguments for format string

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/odoo/custom/src/odoo/odoo/addons/base/ir/ir_http.py", line 208, in _dispatch
    result = request.dispatch()
  File "/opt/odoo/custom/src/odoo/odoo/http.py", line 826, in dispatch
    r = self._call_function(**self.params)
  File "/opt/odoo/custom/src/odoo/odoo/http.py", line 339, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/opt/odoo/custom/src/odoo/odoo/service/model.py", line 97, in wrapper
    return f(dbname, *args, **kwargs)
  File "/opt/odoo/custom/src/odoo/odoo/http.py", line 335, in checked_call
    result.flatten()
  File "/opt/odoo/custom/src/odoo/odoo/http.py", line 1265, in flatten
    self.response.append(self.render())
  File "/opt/odoo/custom/src/odoo/odoo/http.py", line 1258, in render
    return env["ir.ui.view"].render_template(self.template, self.qcontext)
  File "/opt/odoo/custom/src/odoo/odoo/addons/base/ir/ir_ui_view.py", line 1189, in render_template
    return self.browse(self.get_view_id(template)).render(values, engine)
  File "/opt/odoo/auto/addons/website/models/ir_ui_view.py", line 113, in render
    return super(View, self).render(values, engine=engine)
  File "/opt/odoo/auto/addons/web_editor/models/ir_ui_view.py", line 27, in render
    return super(IrUiView, self).render(values=values, engine=engine)
  File "/opt/odoo/custom/src/odoo/odoo/addons/base/ir/ir_ui_view.py", line 1198, in render
    return self.env[engine].render(self.id, qcontext)
  File "/opt/odoo/auto/addons/website_theme_flexible/models/ir_qweb.py", line 21, in render
    **options)
  File "/opt/odoo/custom/src/odoo/odoo/addons/base/ir/ir_qweb/ir_qweb.py", line 57, in render
    return super(IrQWeb, self).render(id_or_xml_id, values=values, **context)
  File "/opt/odoo/custom/src/odoo/odoo/addons/base/ir/ir_qweb/qweb.py", line 271, in render
    self.compile(template, options)(self, body.append, values or {})
  File "/opt/odoo/custom/src/odoo/odoo/addons/base/ir/ir_qweb/qweb.py", line 343, in _compiled_fn
    raise e
  File "/opt/odoo/custom/src/odoo/odoo/addons/base/ir/ir_qweb/qweb.py", line 341, in _compiled_fn
    return compiled(self, append, new, options, log)
  File "<template>", line 1, in template_308_472
  File "/opt/odoo/custom/src/odoo/odoo/addons/base/ir/ir_qweb/qweb.py", line 348, in _compiled_fn
    raise QWebException("Error to render compiling AST", e, path, node and etree.tostring(node[0], encoding='unicode'), name)
odoo.addons.base.ir.ir_qweb.qweb.QWebException: not enough arguments for format string
Traceback (most recent call last):
  File "/opt/odoo/custom/src/odoo/odoo/tools/cache.py", line 84, in lookup
    r = d[key]
  File "/opt/odoo/custom/src/odoo/odoo/tools/func.py", line 68, in wrapper
    return func(self, *args, **kwargs)
  File "/opt/odoo/custom/src/odoo/odoo/tools/lru.py", line 44, in __getitem__
    a = self.d[obj].me
KeyError: ('ir.qweb', <function IrQWeb._get_asset at 0x7fd66096f378>, 'web.assets_frontend', 'en_US', True, False, 'assets', False, (1,))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/odoo/custom/src/odoo/odoo/addons/base/ir/ir_qweb/qweb.py", line 341, in _compiled_fn
    return compiled(self, append, new, options, log)
  File "<template>", line 1, in template_website_layout_505
  File "<template>", line 2, in body_call_content_504
  File "<template>", line 23, in set_485
  File "/opt/odoo/auto/addons/website/models/ir_qweb.py", line 34, in _get_asset
    return super(QWeb, self)._get_asset(xmlid, options, css, js, debug, async, values)
  File "<decorator-gen-37>", line 2, in _get_asset
  File "/opt/odoo/custom/src/odoo/odoo/tools/cache.py", line 89, in lookup
    value = d[key] = self.method(*args, **kwargs)
  File "/opt/odoo/custom/src/odoo/odoo/addons/base/ir/ir_qweb/ir_qweb.py", line 197, in _get_asset
    return asset.to_html(css=css, js=js, debug=debug, async=async, url_for=(values or {}).get('url_for', lambda url: url))
  File "/opt/odoo/custom/src/odoo/odoo/addons/base/ir/ir_qweb/assetsbundle.py", line 109, in to_html
    is_css_preprocessed, old_attachments = self.is_css_preprocessed()
  File "/opt/odoo/custom/src/odoo/odoo/addons/base/ir/ir_qweb/assetsbundle.py", line 315, in is_css_preprocessed
    assets = dict((asset.html_url, asset) for asset in self.stylesheets if isinstance(asset, atype))
  File "/opt/odoo/custom/src/odoo/odoo/addons/base/ir/ir_qweb/assetsbundle.py", line 315, in <genexpr>
    assets = dict((asset.html_url, asset) for asset in self.stylesheets if isinstance(asset, atype))
  File "/opt/odoo/custom/src/odoo/odoo/addons/base/ir/ir_qweb/assetsbundle.py", line 462, in html_url
    return self.html_url_format % self.html_url_args
TypeError: not enough arguments for format string

Error to render compiling AST
TypeError: not enough arguments for format string
Template: website.layout
Path: /templates/t/t/t[6]/t[7]
Node: <t t-call-assets="web.assets_frontend" t-js="false"/>

When uninstalling the module all is ok .. and when comment this file in manifest.py all is ok .. So here is the problem. I don't find any solution yet because I don't understand correctly bundle and debug=assets in odoo I think ...

pedrobaeza commented 6 years ago

@Yajo any clue by your part?

njeudy commented 6 years ago

@pedrobaeza what I understood is odoo try to have an url for those less template file, but have not because it's just template inheritance with inline less code .. (that a good Idea !! ) I never find other module that use it, and when searchin, I find some module that create a controler that return an less file by url with the compiled less code.

@yelizariev you did some brand / debrand module with less and css, did you ever encounter this ?

yajo commented 6 years ago

Sorry, no idea :confused:

tarteo commented 6 years ago

@njeudy In which module is it done by a controller? I need it to be inline because of the qweb variables (we don't want a theme limited by presets).

@pedrobaeza In the constructor of WebAsset (base/ir/ir_qweb/assetsbundle.py) it suggests that inline less is perfectly fine:

        if not inline and not url:
            raise Exception("An asset should either be inlined or url linked, defined in bundle '%s'" % bundle.name)

I think it's an issue of Odoo.

yelizariev commented 6 years ago

Try to include less file, instead of inline less code

tarteo commented 6 years ago

@yelizariev is it possible to print qweb variables in a .less file?

yelizariev commented 6 years ago

I guess no, you need to use presets.

I faced a similar problem with the inline code. It's probably an odoo bug, but it's not a big chance that the will fix it in a short period of time.

tarteo commented 6 years ago

@yelizariev Yea I know normal themes use presets. I can't make millions of presets for each color :P. This module exists because of the flexible setting of colors, fonts, etc. The most I probably can do now is add a note about this in the README file.

treviser commented 6 years ago

I don't know if it is a dumb idea, but when I consider my workflow when designing websites for my customers, I could imagine a situation like this: The module can be used in a design database, while sitting together with the customer until the design is finished as to the customers liking. If it then would be possible to create a theme module based on the actual settings, it would be perfect for my use case. I would then call the module "website_theme_designer". In the most cases I use also other customizations which I have to build into a customer-specific theme module anyway.

njeudy commented 6 years ago

@tarteo : @yelizariev did this in https://github.com/it-projects-llc/misc-addons/blob/11.0/theme_kit/models/res_config.py#L88 .. and less / css was generate here: https://github.com/it-projects-llc/misc-addons/blob/11.0/theme_kit/models/theme.py

think we can use same thing:

changing one value update a view un odoo with less file ... that the mechanisme use when you edit css/less file from web_editor.

image

yelizariev commented 6 years ago

@njeudy thank you, I didn't remember where I faced the problem :smiley:

tarteo commented 6 years ago

@njeudy Thanks! I'll try to make it like that when I get some more time. :+1:

aek commented 5 years ago

I have looked at this today because maybe we could start using this module and have seen this issue. From my experience there will be other issues regarding to the approach used in this module. The actual error is that the styles are generated inline for the assets_frontend bundle and the less preprocessor cannot obtain an url for the content to be saved in the attachments as usually it's done with the rest when apply. Another drawback that came from the usage of conditionals fragments for assets bundles is that their content will be saved into attachments for cache the results so any change to the conditions need to reevaluate the assets bundles in order for the changes to be updated into the attachments generated. In order to fix the actual issue I think that it will be better to: 1- Move the inline styles into independents templates in order to be able to evaluate it. 2- Get the rendered content of the templates saved directly into attachments. 3- Dynamically create or edit a view to extend the needed assets bundle to add the link tag, with the href value pointing to the attachment url, into the target asset bundle. 4- When the conditional values get changed re-evaluate the templates to get and update the attachment content and been able to activate/create/edit the extension view described into the step 3 and remove/clean the needed views extension if you decide to manage more than one view for your templates/attachment content.

I have implemented this kind of Odoo pattern into a module named custom_styles and I use it to be able to manually add custom styles and even js code editable from the Odoo backend without the need to make a custom module to add the file.

You could see it here: https://github.com/aek/aek-odoo/tree/17328f028b5457c71b3726c437c18b4b4b967e01/custom_styles

That module allow you to do this from the Odoo UI but the same could be managed from the website model write to be able to trigger the attachment content update and view extension inheritance links into the asset bundle