I wanted to post this bug here before I post in Gi...
# prefect-community
I wanted to post this bug here before I post in Github, maybe I’m missing something easy to fix. I created an email block in the UI. Let’s call it
I have tried two different methods to access the block in my code. Method 1:
Copy code
from prefect.blocks.notifications import NotificationBlock

email = NotificationBlock().load('Email/test')
and I get the following error
Copy code
File PYTHON/site-packages/prefect/blocks/core.py:836, in Block.__new__(cls, **kwargs)
    834     return m
    835 else:
--> 836     m = super().__new__(cls)
    837     object.__setattr__(m, "__dict__", kwargs)
    838     object.__setattr__(m, "__fields_set__", set(kwargs.keys()))

TypeError: Can't instantiate abstract class NotificationBlock with abstract method notify
It turns out this error comes from any attempt to instantiate
. Can anyone else confirm this error when instantiating? Method 2:
Copy code
from prefect.blocks.core import Block

email = Block().load('Email/test')
and I get the following error
Copy code
File PYTHON/site-packages/prefect/blocks/core.py:646, in Block.load(cls, name)
    642         block_document = await client.read_block_document_by_name(
    643             name=block_document_name, block_type_slug=block_type_slug
    644         )
    645     except prefect.exceptions.ObjectNotFound as e:
--> 646         raise ValueError(
    647             f"Unable to find block document named {block_document_name} for block type {block_type_slug}"
    648         ) from e
    649 return cls._from_block_document(block_document)

ValueError: Unable to find block document named test for block type Email
even though the block has def been created in the UI. Have I tried the right things? Is there some other way to access my Email block? Or is this a real bug? PS (I see Mohamed Alaa write about a similar bug in this thread a few hours ago)
Hello Erik, I'm actually having the same difficulty too. I posted a question yesterday. You could refer to it in case someone came with a solution on my thread https://prefect-community.slack.com/archives/CL09KU1K7/p1663777217452139
Haha just saw that! I read the replies and will keep an eye on it, but I also wanted to point out that NotificationBlock() is 100% broken as well, apparently. Thanks for staying on it! Hope to get a solution soon.
Yea, I think there is something broken with the Blocks logic. Hope so too!
@Erik just remove the parentheses in
and you should be good to go. 🙂
@Jeff Hale Ok I see that, but now I’m still getting this error.
ValueError: Unable to find block document named test for block type Email
It also should be noted that when I try
(lowercase) I get this.
KeyError: "No class found for dispatch key 'email' in registry for type 'Block'."
even though the prefect CLI
prefect block ls
says that is the “slug”
Hi Erik. Please check out the link to Mohamed’s post above, you need to import the class. I know that’s not super intuitive and I discussed the issue with the team today.
@Jeff Hale glad to hear that it’s being discussed. From
I can import
, and
Block types, but how do I import the
block class type, I can’t seem to find it.
I also checked the API ref in the docs and didn’t find it anywhere
This is interesting. Different issue than what I was looking at earlier, apologies. I’ve send a request to the team to get more insight into the issue and will let you know when I hear back. 🙂
ok great! glad to know I’m not going insane! Thanks for your help. Will use slackwebhook until the email thing gets fixed. 🙏
Alright, I learned something new: That block is only useable server side in Cloud - we clearly need to communicate that better in the GUI. Solutions: You can use the prefect-email collection with your own SendGrid account if you want to use email in flows. There’s documentation at the README. Alternatively, the solution for state changes for flows is easier, you can just use email notifications from the Notifications tab in the Cloud GUI. Apologies that you were spinning your wheels. 🙂
Gotcha. Sounds like y’all need a SMTP block! but maybe I’ll just make a custom one. Should be easy enough. Thanks for following up.