# Forcing dependencies in python model

**URL:** <https://discourse.getdbt.com/t/forcing-dependencies-in-python-model/18346>\
**Category:** Help\
**Created:** [February 21, 2025, 11:09am UTC](https://discourse.getdbt.com/t/forcing-dependencies-in-python-model/18346 "2025-02-21T11:09:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mick](https://avatars.discourse-cdn.com/v4/letter/m/f04885/32.png) [@mick](https://discourse.getdbt.com/u/mick)\
**Post date:** [February 21, 2025, 11:09am UTC](https://discourse.getdbt.com/t/forcing-dependencies-in-python-model/18346/1 "2025-02-21T11:09:12Z")

</div>

In my python model I am using session.sql(my\_query).

I can’t use dbt.ref because that will load the entire upstream dataset at once, which is too big for my memory limitations. Instead, I loop over segments of this data set by updating `my_query` with a dynamic where clause. (If anyone has a nicer suggestion for this, let me know). This all works well, but because I use session.sql instead of dbt.ref, the upstream view I use isn’t added to the lineage. So when I call dbt build -s +this\_model, the upstream view won’t run.

Now, for sql models you can add the ref to a comment, like  
– depends\_on: {{ ref(‘upstream\_parent\_model’) }} - from [About ref function | dbt Developer Hub](https://docs.getdbt.com/reference/dbt-jinja-functions/ref)

So my question is: is there an equivalent for python?

Thanks!
