Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] t-if not condition #1399

Closed
mervick opened this issue Apr 11, 2023 · 2 comments
Closed

[BUG] t-if not condition #1399

mervick opened this issue Apr 11, 2023 · 2 comments
Labels
wontfix This will not be worked on

Comments

@mervick
Copy link

mervick commented Apr 11, 2023

<t t-if="not condition">

raises error:

OwlError: An error occured in the owl lifecycle (see this Error's "cause" property)
    at handleError (/web/assets/1182-077fe86/web.assets_common.min.js:1247:101)
    at owl.App.handleError (web/assets/1182-077fe86/web.assets_common.min.js:2077:29)
    at Fiber._render (/web/assets/1182-077fe86/web.assets_common.min.js:1478:19)
    at Fiber.render (/web/assets/1182-077fe86/web.assets_common.min.js:1476:6)
    at ComponentNode.initiateRender (web/assets/1182-077fe86/web.assets_common.min.js:1555:47)

Caused by: SyntaxError: Unexpected identifier 'ctx'
    at new Function (<anonymous>)
    at compile (/web/assets/1182-077fe86/web.assets_common.min.js:2040:370)
    at owl.App._compileTemplate (/web/assets/1182-077fe86/web.assets_common.min.js:2095:300)
    at owl.App._compileTemplate (/web/assets/1182-077fe86/web.assets_common.min.js:2105:83)
    at owl.App.getTemplate (/web/assets/1182-077fe86/web.assets_common.min.js:1699:118)
    at new ComponentNode (/web/assets/1182-077fe86/web.assets_common.min.js:1550:133)
    at /web/assets/1182-077fe86/web.assets_common.min.js:2075:6
    at Field.template (eval at compile (/web/assets/1182-077fe86/web.assets_common.min.js:2040:370), <anonymous>:18:31)
    at Fiber._render (/web/assets/1182-077fe86/web.assets_common.min.js:1477:96)
    at Fiber.render (/web/assets/1182-077fe86/web.assets_common.min.js:1476:6)

but this works as expected:

<t t-if="! condition">
@ged-odoo
Copy link
Contributor

This is because Owl evaluates expressions as javascript (with some additional allowed words, see https://github.com/odoo/owl/blob/master/doc/reference/templates.md#expression-evaluation). So, we allow the use of and, or, gte, lte, gt, lt.

Since not is not part of the spec (as far as I know), it has not been translated into !, which is why your code fails. So:

  • we can update the spec and add it to the list of keywords that are replaced
  • just not do anything.

I am not completely comfortable with increasing the distance between the expression in the template and the corresponding javascript expression, so I think that in this case, the correct decision is to just keep owl as it is.

@sdegueldre
Copy link
Contributor

sdegueldre commented Apr 11, 2023

I agree with Géry. The reason the other ones are supported is to avoid having to use encoded XML entities in the middle of expressions as it greatly reduces legibility, in particular & and < need to be encoded in attributes, which is why we have to allow for alternate forms of &&, < and <=. The rest exist for consistency/symmetry of comparisons even though they're not stricly needed. The purpose here is not to allow python syntax in expressions, in fact none of the comparisons are valid python anyway, but I can understand why one might think that. We should probably clarify the docs on that front. We could even enable a warning at compilation time in dev mode, since not is probably not a common variable name.

@sdegueldre sdegueldre closed this as not planned Won't fix, can't repro, duplicate, stale Apr 11, 2023
@sdegueldre sdegueldre added the wontfix This will not be worked on label Apr 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants