Git Product home page Git Product logo

Comments (5)

haritamar avatar haritamar commented on May 24, 2024

Hi @ahmedhamidibr !
Thanks for posting this issue and sorry for the late response.

Is this issue still relevant to you?
If so - one question - any chance your project overrides the source macro?

from elementary.

ahmedhamidibr avatar ahmedhamidibr commented on May 24, 2024

Hi @haritamar,

Yes, indeed, my project overrides the source macro. It turns out that was the cause. After resetting back to the default source macro, it worked as expected. However, I remain interested in any workaround you might suggest to ensure the tests continue to work even when the source macro is overridden.

from elementary.

haritamar avatar haritamar commented on May 24, 2024

Hi @ahmedhamidibr ,
So the main issue is that for the schema_changes_from_baseline test to work, Elementary needs to ontain a dbt Relation object which allows us to get the current columns of the table.
When you override the source macro (or ref for that matter), you have the ability to return a query string instead of a relation object - which works for many dbt use-cases but is problematic for Elementary's tests due to the reason above.

So there are two workarounds that can be done until we support this use case, depending on what exactly your overriding source macro does:

  • If it's possible to change your macro to return a dbt Relation object instead of a string (here's a dbt example for the ref macro, but a similar thing can be done for sources) then it should help solve the issue. This may be doable if your macro returns a database table (and not a select query).
  • If on the other hand you actually return a query (e.g. if you're doing some filtering), then a possible (hacky) workaround would be to make the macro only return a Relation object when it's run from the context of the schema_changes_from_baseline test, e.g.:
{% set model_node = context.get("model") %}
{% if model_node and model_node.get("resource_type") == "test" and model_node["test_metadata"]["name"] == "schema_changes_from_baseline" %}
    {% do return(builtins.source(source_name, table_name)) %}
{% endif %}

... do more complex logic that returns a query ...

from elementary.

ahmedhamidibr avatar ahmedhamidibr commented on May 24, 2024

@haritamar Thank you so much, this did the trick!

from elementary.

haritamar avatar haritamar commented on May 24, 2024

Glad to hear @ahmedhamidibr !

from elementary.

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.