https://prefect.io logo
t

Tim Wisniewski

03/09/2023, 4:28 PM
Hey all, I've spent the last two days trying to learn the ropes of Prefect, and I've made a lot of progress, but I have a feeling I may be using prefect-sqlalchemy fundamentally the wrong way. Would someone mind taking a quick glance at my workflow and telling me if I'm on the right track, or way off? https://gist.github.com/timwis/50fe4e90e052475e01d357e9b6142374#file-sync-py-L37 (In particular, I have a feeling the way I'm using Sessions is wrong, because the docs for prefect-sqlalchemy don't mention how to use it with ORM, so I took a bit of a leap)
n

Nate

03/09/2023, 5:19 PM
Hi @Tim Wisniewski Using
prefect-sqlalchemy
as a way of retrieving a db engine seems totally valid to me I can't say I know what's happening with your session commit though. As a sanity check, does it do the same thing if you remove the
@task
decorator for
get_job_definitions
and
renew_token
?
t

Tim Wisniewski

03/09/2023, 7:34 PM
Thanks Nate that’s great to hear. Appreciate you taking a look. I assumed the issue was because I had two different sessions - one for querying and one for updating (I’m used to rails/active record, where we wouldn’t need to define sessions to read/update models), but I’ll try that.
Yep, that was it—it's because I was using two different sessions. I had to
session.add()
that object, but I also had to configure my session to
expire_on_commit=False
. Starting to wonder if, instead, I should create the session in my
@flow
and pass it to each database
@task
🤔