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

Debug macros not executing in dbt testing environment #154

Open
lorerod opened this issue Aug 29, 2024 · 2 comments
Open

Debug macros not executing in dbt testing environment #154

lorerod opened this issue Aug 29, 2024 · 2 comments
Assignees

Comments

@lorerod
Copy link
Contributor

lorerod commented Aug 29, 2024

I tried implementing unit tests for incremental tables as part of Enhance DBT models testing work. But the incremental conditions depend on the max_existing_timestamp macro, which is not working in the test environment.

Investigate why macros don't work in the testing environment.

@lorerod lorerod self-assigned this Aug 29, 2024
@andrablaj
Copy link
Member

@witash any chance this is solved in the issue #144 you are working on?

@lorerod
Copy link
Contributor Author

lorerod commented Sep 4, 2024

The test I tried to implement for the person incremental model:

- name: test_person_model_transformation_and_data_integrity_incremental
    model: person
    overrides:
      macros:
        # unit test this model in "incremental" mode
        is_incremental: true
    given:
      - input: ref('contact')
        format: csv
        fixture: person_contact_initial
      - input: source('couchdb', "{{ env_var('POSTGRES_TABLE') }}")
        format: csv
        fixture: person_source_table_initial
      - input: this
        # contents of current my_incremental_model
        rows:
          - { uuid: p1,saved_timestamp: 2024-08-01 00:00:00,date_of_birth: 1980-01-01,sex: M}
          - { uuid: p2,saved_timestamp: 2024-08-01 00:00:00,date_of_birth: 1990-05-15,sex: F}
    expect:
      # what will be inserted/merged into my_incremental_model
      rows:
        - { uuid: p1,saved_timestamp: 2024-08-01 00:00:00,date_of_birth: 1980-01-01,sex: M}
        - { uuid: p2,saved_timestamp: 2024-08-01 00:00:00,date_of_birth: 1990-05-15,sex: F}

The output in dbt/logs/dbt.log:

[0m16:04:27.495212 [debug] [Thread-1 (]: Began running node unit_test.cht_pipeline_base.person.test_person_model_transformation_and_data_integrity_incremental
�[0m16:04:27.496010 [info ] [Thread-1 (]: 33 of 35 START unit_test person::test_person_model_transformation_and_data_integrity_incremental  [RUN]
�[0m16:04:27.497186 [debug] [Thread-1 (]: Re-using an available connection from the pool (formerly unit_test.cht_pipeline_base.person.test_person_model_transformation_and_data_integrity, now unit_test.cht_pipeline_base.person.test_person_model_transformation_and_data_integrity_incremental)
�[0m16:04:27.498039 [debug] [Thread-1 (]: Began compiling node unit_test.cht_pipeline_base.person.test_person_model_transformation_and_data_integrity_incremental
�[0m16:04:27.498479 [debug] [Thread-1 (]: Began executing node unit_test.cht_pipeline_base.person.test_person_model_transformation_and_data_integrity_incremental
�[0m16:04:27.518147 [debug] [Thread-1 (]: Using postgres connection "unit_test.cht_pipeline_base.person.test_person_model_transformation_and_data_integrity_incremental"
�[0m16:04:27.518832 [debug] [Thread-1 (]: On unit_test.cht_pipeline_base.person.test_person_model_transformation_and_data_integrity_incremental: BEGIN
�[0m16:04:27.519298 [debug] [Thread-1 (]: Opening a new connection, currently in state closed
�[0m16:04:27.528900 [debug] [Thread-1 (]: SQL status: BEGIN in 0.009 seconds
�[0m16:04:27.529879 [debug] [Thread-1 (]: Using postgres connection "unit_test.cht_pipeline_base.person.test_person_model_transformation_and_data_integrity_incremental"
�[0m16:04:27.530839 [debug] [Thread-1 (]: On unit_test.cht_pipeline_base.person.test_person_model_transformation_and_data_integrity_incremental: /* {"app": "dbt", "dbt_version": "1.8.6", "profile_name": "default", "target_name": "test", "node_id": "unit_test.cht_pipeline_base.person.test_person_model_transformation_and_data_integrity_incremental"} */
SELECT max(saved_timestamp) as max_existing
        FROM "".""
�[0m16:04:27.532267 [debug] [Thread-1 (]: Postgres adapter: Postgres error: zero-length delimited identifier at or near """"
LINE 3:         FROM "".""
                     ^

�[0m16:04:27.533124 [debug] [Thread-1 (]: On unit_test.cht_pipeline_base.person.test_person_model_transformation_and_data_integrity_incremental: ROLLBACK
�[0m16:04:27.537942 [debug] [Thread-1 (]: On unit_test.cht_pipeline_base.person.test_person_model_transformation_and_data_integrity_incremental: Close
�[0m16:04:27.543425 [debug] [Thread-1 (]: Database Error in unit_test test_person_model_transformation_and_data_integrity_incremental (models/contacts/tests/persons.yml)
  zero-length delimited identifier at or near """"
  LINE 3:         FROM "".""
                       ^
�[0m16:04:27.544162 [error] [Thread-1 (]: 33 of 35 ERROR person::test_person_model_transformation_and_data_integrity_incremental  [�[31mERROR�[0m in 0.05s]
�[0m16:04:27.546269 [debug] [Thread-1 (]: Finished running node unit_test.cht_pipeline_base.person.test_person_model_transformation_and_data_integrity_incremental

The error might be related to this context in the macro not being correctly resolved or improperly formatted in the test env.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

2 participants