Nomada
April 28, 2023, 4:28am
1
I am trying to create a new python model inside a folder that already contains python models. But whenever I try to do that, I get an error that says that dbt only allows one model per python file.
This is the complete error:
Parsing Error in model (path/to_model/name.py)
dbt only allow one model defined per python file
Hi! Take a look at this issue, see if it helps you
opened 03:16PM - 13 Oct 22 UTC
closed 06:59PM - 14 Oct 22 UTC
bug
regression
python_models
### Is this a regression in a recent version of dbt-core?
- [X] I believe thi… s is a regression in dbt-core functionality
- [X] I have searched the existing issues, and I could not find an existing issue for this regression
### Current Behavior
We have been structuring our projects to have the models_path pointing to folders that contains both dbt code (in .sql files) and other python code used for extract-load the data, or run some light modelling. This simplifies our repo structure a lot and has been very convenience to work with (compared to the default approach of having a separate dbt folder).
However, since v1.3.0 we're failing to run any dbt model (sql) due to this error
```
Parsing Error in model the_unrelated_python_file
dbt only allow one model defined per python file
```
We realize this is due to the new version starting looking into .py files to find models, and assuming all .py files are dbt-related.
### Expected/Previous Behavior
While I look forward to using dbt Python model, I don't think this feature should inhibit the ability of having other type of Python files in the same folder.
I'd suggest to either
- ignore .py files that don't have a specific dbt marker
- allow a project config to turn off the use of dbt Python altogether (we use Redshift so it's not even supported yet I believe)
### Steps To Reproduce
1. Have a dbt project. Inside the model-path folder, put:
- a sql dbt model
- a non-dbt Python file which contains more than 1 class definition.
2. Run `dbt run -s the_sql_model`
3. See the error
### Relevant log output
_No response_
### Environment
```markdown
- OS: Ubuntu 20.04
- Python: 3.8
- dbt (working version): <=1.2.2
- dbt (regression version): 1.3.0
```
### Which database adapter are you using with dbt?
redshift
### Additional Context
_No response_
Nomada
April 28, 2023, 1:12pm
3
Thank you @brunoszdl ! I read it, but not sure what will do this .dbtignore to my other python models already in that folder. I have scheduled jobs that use those other python models, and I don’t want to break them. Do you know of this is the case?
Adding .dbtignore
file in root directory(same level as dbt_project.yml
) solved my problem.
Ref: .dbtignore | dbt Developer Hub