GithubHelp home page GithubHelp logo

Comments (9)

YetAnotherMinion avatar YetAnotherMinion commented on August 17, 2024

probably wants a default argument, which in this case would be

{%- if not salt.get('postgres.user_create', False) %}

from postgres-formula.

vutny avatar vutny commented on August 17, 2024

@fcrozat Thanks for you report.

I've tested the code with Salt 2016.3.4 and 2016.11.1 many times and it always works fine for me. Maybe it is related to particular jinja module version installed...

Try to replace the line with the following:

{%- if 'postgres.user_create' not in salt.keys() %}

I hope this will help. If so, we update the code accordingly.

from postgres-formula.

fcrozat avatar fcrozat commented on August 17, 2024

changing to {%- if not salt.get('postgres.user_create', False) %} works fine.

other proposed fix ( %- if 'postgres.user_create' not in salt.keys() %} )doesn't work:

  • Rendering SLS 'base:postgres.manage' failed: Jinja error: 'FunctionWrapper' object has no attribute 'call'
    Traceback (most recent call last):
    File "/usr/lib/python2.7/site-packages/salt/utils/templates.py", line 368, in render_jinja_tmpl
    output = template.render(**decoded_context)
    File "/usr/lib/python2.7/site-packages/jinja2/environment.py", line 989, in render
    return self.environment.handle_exception(exc_info, True)
    File "/usr/lib/python2.7/site-packages/jinja2/environment.py", line 754, in handle_exception
    reraise(exc_type, exc_value, tb)
    File "", line 5, in top-level template code
    AttributeError: 'FunctionWrapper' object has no attribute 'call'

    ; line 5
    
    ---
    {%- from "postgres/map.jinja" import postgres with context -%}
    {%- from "postgres/macros.jinja" import format_state with context -%}
    
    {# }{%- if not salt.get('postgres.user_create') %} #}
    {%- if 'postgres.user_create' not in salt.keys() %}    <======================
    
    # Salt states for managing PostgreSQL is not available,
    # need to provision client binaries first
    
    include:
    [...]
    ---
    

from postgres-formula.

vutny avatar vutny commented on August 17, 2024

@fcrozat Thanks a lot for testing.
This is very interesting, it looks like ordinary Python methods cannot be reliably used for special Jinja objects such as salt, at least in your case. And I think the get() method cannot be fully trusted here to do the job I thought it was supposed to do.

Please, could you try the last one code snippet since only you are able to reproduce the issue?
Check this out if it would work:

{%- if salt['postgres.user_create']|default(none) is not callable %}

I assume this is the safest check for the exec module function present (and actually is a function) in the state run scope.

Thanks again for your involvement.

from postgres-formula.

fcrozat avatar fcrozat commented on August 17, 2024

I can confirm the latest proposed fix works fine here.

from postgres-formula.

vutny avatar vutny commented on August 17, 2024

Cool! That was very helpful, @fcrozat. Soon I will come up with a PR to fix this and other similar calls to the salt object across the formula.

from postgres-formula.

vutny avatar vutny commented on August 17, 2024

I have submitted PR #150 to address this issue.

from postgres-formula.

vutny avatar vutny commented on August 17, 2024

@fcrozat PR #150 has been merged. I think this issue could be closed. Thanks for your participation!

from postgres-formula.

vutny avatar vutny commented on August 17, 2024

@javierbertoli Since this is already resolved, please close it out. Thanks!

from postgres-formula.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.