Adding Query Tag to DBT Test - tags

I would like to kindly ask you about adding query tags for Snowflake queries to dbt tests.
Is there any way to add query tags for tests to project or schema yaml file? I have tried but I could not find a way for it.
I can modify some packages like dbt_utils.unique_combination_of_columns.combination_of_columns adding query tag statement. But if I use the schema tests in the yaml like below, where and how can I define the query tags for tests?
models:
name: dim_customers
columns:
- name: company
tests:
- not_null
- unique

The default macro in the dbt package for snowflake, in line 3 calls a macro named set_query_tag(), that it's defined here. What you can do is to create a custom set_query_tag() in your dbt project, following this example (taken from here):
{% macro set_query_tag() -%}
{# select some property of the node #}
{% set new_query_tag = model.name %}
{% if new_query_tag %}
{% set original_query_tag = get_current_query_tag() %}
{{ log("Setting query_tag to '" ~ new_query_tag ~ "'. Will reset to '" ~ original_query_tag ~ "' after materialization.") }}
{% do run_query("alter session set query_tag = '{}'".format(new_query_tag)) %}
{{ return(original_query_tag)}}
{% endif %}
{{ return(none)}}
{% endmacro %}
This will override the default macro and tag all your runs with the test name (something like not_null__model_name__column_name). If you only want to do it with tests, you need to add some extra if/else using
node.resource_type == 'test'
Also, check this it seems that this is possible since a few days ago, so it could now work as expected with older versions...

Related

orocommerce wysiwyg editor - file / image wrong src

I have similar issue that Wysiwyg images not moved to public cache
when I add a file or image in wysiwyg, it displays properly in editor but after saving, it doesn't display in admin nor front.
Generated markup src is incorrect/not properly replaced:
<picture id="irozi"><source srcset="{{ wysiwyg_image('22','d9ffaffc-f286-4707-bd4b-29504628acc2','wysiwyg_original','webp') }}" type="image/webp"><img src="{{ wysiwyg_image('22','0872c470-f50a-4290-8043-96ffd5e205d2','wysiwyg_original','') }}" id="icysf" alt="test picture"></picture>
my-file.csv
My field already exists (in a custom bundle) and "File applications" doesn't show in "Entity Management".
Do I need that conf? How to achieve it with a migration?
What else should I do to have a correct src for files and images?
File applications config is required if you want to display an image that is ACL protected within the application. You can set it using a migration, e.g.:
$queries->addQuery(
new UpdateEntityConfigFieldValueQuery(
'Acme\Demobundle\Entity\FancyFile',
'image',
'attachment',
'file_applications',
['default', 'commerce']
)
);
The issue might also be related to image processing. Please, check the log file for errors.
UPDATE
Also, as a WYSIWYG field has some twig placeholders it has to be rendered with the applied postprocessing.
On the storefront it should be rendered with:
{% if entity.contentStyle|length -%}
{%- apply spaceless -%}
<style type="text/css">{{ entity.contentStyle|render_content }}</style>
{%- endapply -%}
{%- endif %}
{{ entity.content|render_content }}
There are also ready-to-use layout block types: wysiwyg_style and text_with_placeholders.
On the back-office there is a macro
{% import '#OroEntityConfig/macros.html.twig' as entityConfig %}
{{ entityConfig.renderWysiwygContentPreview(entity.content)|raw }}
Where the entity.content is the field path to render.
The team will update the documentation to mention that.

How to remove empty categories?

I have a two scenarios to solve :)
Let's say I built plugin (with builder) where I have products and categories.
Now on page with listed categories I have all of them, but I want to not display empty categories.
How to remove empty categories form listing?
Second scenario. Some of products have options and some none.
Products and options have relation table.
On single product page I have some like:
product description
options for this product
(that work well)
But in case of product doesn't have any options I want to have:
product description
text "this product have no options" (or not display any text at all)
So far I have tried something like:
{{ if option in record.options == true }}
display options
{{ else }}
"this product have no options"
{{ endif }}
But this doesn't work at all.
Is there a way to check for existing options for product?
Thanks for your time.
For Question number 1
Here you can put a condition on $query->has('products', '>', 0) but seems you are using the builder plugin so you can simply put a condition on the category product count.
{% for category in categories %}
{% if category.products|length > 0 %}
{{category.name}}. // here you will get only category which has products.
{% endif %}
{% endfor %}
For Question number 2
You can do something like this
{% if record.options|length > 0 %}
show them
{% else %}
no options
{% endif %}
if any doubt please comment.

DBT Macros to perform computations

i was trying to write a macros which would be capable of doing various computations and return the final result.
Does macros accept only Block level codes like if or for loops? and not set of individual statements?
please help me with this
Thanks
There's a lot you can do with macros. Most native python operations are possible, albeit in a clunky non-pythonic way (no list comprehensions here).
For example, one can call any method of a python builtin data type:
{% set my_base_models = [] %}
{% for i in graph.nodes.values() %}
{% if i["name"].startswith('base_model') %}
{% do my_list.append(i) %}
{% endif %}
{% endfor %}
Key points:
call {% do <obj>.<method>() %} with any state-altering method (eg. pop() , append(), etc) to execute it
Put results into variables with {% set <var> = <expression> %}
Check out out filters and tests in standard jinja to filter and test mappings (dicts) and lists
Check out the list of dbt specific jinja context variables and methods

Filtering by tag shows all pages instead of tagged pages

With reference to the Wagtial recipe on tags, I have set up tags in my courses app. However, tag filtering does not seem to be working. The tags themselves seem to be working: I can select tags in the admin and show them on the page. I have a course page tag model that seems to be working properly:
class CoursePageTag(TaggedItemBase):
content_object = ParentalKey('CoursePage',
on_delete=models.CASCADE,
related_name='course_tagged_items')
I have filtering setup in the CourseListingPage model (with template = "courses/course_listing_page.html") like this:
# Get all courses
course_pages = (
CoursePage.objects.live().public().order_by("-first_published_at")
)
# Filter by tag
tag = request.GET.get('tag')
if tag:
course_pages = course_pages.filter(tags__name=tag)
context['course_pages'] = course_pages
return context
And in the template I have this:
{% for tag in page.tags.all %}
{{ tag }}
{% endfor %}
When I click a tag on a course page with the above template code, I do arrive at the parent course listing page, and the URL shows what seems to be the correct filtering format:
courses/course-listing/?tag=test
But I do not see a filtered list of pages. Instead I see all course pages. I suspect there is something very simple that I am doing wrong here.
Answering my own question: {% for course in course_pages %} is required in the template at the location of the listing of the filtered pages -- in my case, below the filtering code. So, I now have the filtering code, then the actual listing of the pages, which begins with:
{% for course in course_pages %}
{% with course=course.specific %}
... HTML/template code for page details (e.g. course.title, course.sub_title) ...
{% endfor %}
{% endwith %}
I didn't initially that realize that the filtering code only does the filtering; it doesn't actually show the results of the filtering. For a beginner like me, when the docs say that the code will filter the listing to only those pages with a matching tag name before passing this to the template for rendering, it's possible to misread this to mean that the template will show the filtered results without further steps. But that's not the case. The extra contextual code is required -- at least it was for me.

Errors for form in rendered template

I have this :
template edit.html.twig
{% extends "....:...:layout.html.twig" %}
{% block body %}
{{ render(controller('EVeilleurFlowerBundle:Catalogue:add' )) }}
{{ render(controller('EVeilleurFlowerBundle:Catalogue:delete' )) }}
{% endblock %}
And the template "add" is basically a single form.
When the user enters "wrong" data in the add form, it automatically redirects to add.html.twig, displaying a single form ( wtih the error ) without layout, css etc...
Can i change the redirection, or am I building my templates the wrong way ? (pretty much newbie here :) )
Thanks