dbeatty10 / dbt-mysql

dbt-mysql contains all of the code enabling dbt to work with MySQL and MariaDB
Apache License 2.0
75 stars 53 forks source link

rename_relation macro in adapters does not work when relation is a view. #158

Closed hermandr closed 10 months ago

hermandr commented 10 months ago

Describe the bug

When a model is defined as a view and then changed, SQL DB call does not return. Using mariadb adapter

Steps To Reproduce

  1. define a model - default it is a view
  2. dbt run
  3. Edit the view
  4. dbt run
  5. Does not return

Expected behavior

Drop and Replace View

Screenshots and log output

If applicable, add screenshots or log output to help explain your problem.

02:40:12.048104 [debug] [Thread-1  ]: Began running node model.my_project.base_contract
02:40:12.048353 [info ] [Thread-1  ]: 1 of 1 START sql view model app.base_contract .................................. [RUN]
02:40:12.048695 [debug] [Thread-1  ]: Acquiring new mariadb connection 'model.my_project.base_contract'
02:40:12.048831 [debug] [Thread-1  ]: Began compiling node model.my_project.base_contract
02:40:12.050864 [debug] [Thread-1  ]: Writing injected SQL for node "model.my_project.base_contract"
02:40:12.051131 [debug] [Thread-1  ]: Timing info for model.my_project.base_contract (compile): 2023-11-14 02:40:12.048922 => 2023-11-14 02:40:12.051086
02:40:12.051266 [debug] [Thread-1  ]: Began executing node model.my_project.base_contract
02:40:12.073324 [debug] [Thread-1  ]: Using mariadb connection "model.my_project.base_contract"
02:40:12.073495 [debug] [Thread-1  ]: On model.my_project.base_contract: /* {"app": "dbt", "dbt_version": "1.4.9", "profile_name": "my_project", "target_name": "stg", "node_id": "model.my_project.base_contract"} */
drop view if exists `app`.`base_contract__dbt_tmp`
02:40:12.073596 [debug] [Thread-1  ]: Opening a new connection, currently in state closed
02:40:13.282989 [debug] [Thread-1  ]: SQL status: SUCCESS 0 in 1 seconds
02:40:13.287452 [debug] [Thread-1  ]: Writing runtime sql for node "model.my_project.base_contract"
02:40:13.287765 [debug] [Thread-1  ]: Using mariadb connection "model.my_project.base_contract"
02:40:13.287893 [debug] [Thread-1  ]: On model.my_project.base_contract: BEGIN
02:40:13.554005 [debug] [Thread-1  ]: SQL status: SUCCESS 0 in 0 seconds
02:40:13.554500 [debug] [Thread-1  ]: Using mariadb connection "model.my_project.base_contract"
02:40:13.554769 [debug] [Thread-1  ]: On model.my_project.base_contract: /* {"app": "dbt", "dbt_version": "1.4.9", "profile_name": "my_project", "target_name": "stg", "node_id": "model.my_project.base_contract"} */

  create view `app`.`base_contract__dbt_tmp` as
    -- extracted from information schema
select
    `id`,
    `vid`,
    `uuid`,
    `revision_translation_affected`,
    `deleted`,
   ... many columns ...
from `app`.`im_contract`
02:40:13.828927 [debug] [Thread-1  ]: SQL status: SUCCESS 0 in 0 seconds
02:40:13.832996 [debug] [Thread-1  ]: Using mariadb connection "model.my_project.base_contract"
02:40:13.833152 [debug] [Thread-1  ]: On model.my_project.base_contract: /* {"app": "dbt", "dbt_version": "1.4.9", "profile_name": "my_project", "target_name": "stg", "node_id": "model.my_project.base_contract"} */

    drop view if exists `app`.`base_contract__dbt_backup` cascade

02:40:14.099785 [debug] [Thread-1  ]: SQL status: SUCCESS 0 in 0 seconds
02:40:14.100471 [debug] [Thread-1  ]: Using mariadb connection "model.my_project.base_contract"
02:40:14.100615 [debug] [Thread-1  ]: On model.my_project.base_contract: /* {"app": "dbt", "dbt_version": "1.4.9", "profile_name": "my_project", "target_name": "stg", "node_id": "model.my_project.base_contract"} */

    rename table `app`.`base_contract` to `app`.`base_contract__dbt_backup`

The output of dbt --version:

03:21:25  Running with dbt=1.4.9
dbt version: 1.4.9

The operating system you're using:

Distributor ID: Ubuntu
Description:    Ubuntu 22.04.1 LTS
Release:        22.04
Codename:       jammy

The output of python --version:

python version: 3.8.16

Additional context

hermandr commented 10 months ago

I encountered this problem only for one view. It works for other views. I believe it is a problem with the db not with dbt.