I've read the intro docs and went through the tuto...
# prefect-community
j
I've read the intro docs and went through the tutorial and was trying out some Prefect Tasks. First off was MySqlFetch because, well MySql.... I feel like I've got things setup right but I'm running into an unexpected error in the task runner trying to do a
MySqlFetch.run()
. :
Copy code
ERROR:prefect.TaskRunner:Unexpected error: AttributeError('__enter__',)
So I didn't want to get into debugging this because my code could be totally wrong. I was hoping to find some examples of using this and other Prefect Tasks. Are there examples for how to use this and other tasks?
c
Hi @James Bennett Saxon - I can take a look at the code for that particular task, but a large portion of our tasks are community contributed (including
MySqlFetch
) so the documentation varies
j
Hey there @James Bennett Saxon — looking at the
MySqlFetch
task’s code, it looks like it attempts to enter two different context managers to open a transaction - is it possible that it’s failing to connect, so
conn
is an object like None? That code is here.
I’m not sure what pymysql returns as
conn
if the connection fails
j
Thanks guys for the clues. It clarifies a lot.
Yes, that is where it's raising the exception. So it makes sense that something happened on the connection.
Okay, so sorry for the python question here but if I wanted to go ahead and fork/clone/develop the package so I can more cleanly debug... (and maybe contribute back), what's the trick?
c
check out these docs on contributing: https://docs.prefect.io/core/development/overview.html Feel free to ask any questions if you get stuck; we also have a channel #prefect-contributors dedicated to helping both new and seasoned contributors!
j
Heh! Thanks Chris! I had realized I cloned the whole repo setting up the tutorial! So, I'm off to the races debugging. That the one exception is handling both pymysql errors AND any other Exception, causes the amgibuity. It appears the conn is created just fine, but it's got no
__enter__
! Why not? Maybe I've got version issues...
Lol, Commented out the outer context manager and at least with a valid connection, it's working!
c
Nice @James Bennett Saxon! Sounds like we need to remove the outer context manager - if you’d like to make a PR for this let me know
j
👌
j
I can give it a shot! My hacking is pretty good, my polishing... Well, that's the hard part! 🙂
c
Haha no worries - we can work with you and provide suggestions 👍
👍 1
j
@Chris White Hey, so I'm stepping into this very very lightly as I'd love to help but I've got a lot going on... I went ahead and forked and branched and tweaked the code a bit. I tried to push for more coverage and built dummies rather than mocks (for pymysql), and I've run black and mypy on it. I also realized that in core, you've got the postgres version which looks identical. If you want, I can make a PR (to what branch) or you can review and or take it from here or whatnot? If there's no rush, then let me know and I'll see when I've got another shot at responding to comments! 🙂 Thanks for the nudge. https://github.com/PrefectHQ/prefect/compare/master...ijames:contrib-mysql-fix-context-manager?expand=1