<@ULVA73B9P> I am trying to copy over a block conf...
# ask-community
k
@Marvin I am trying to copy over a block configuration from a self hosted prefect server to another identical self hosted prefect server. I have pulled the block document from one server, and am using the client.create_block_document() function to apply the block document to another server. However, I am getting an error. Specifically, with the block_type_id. Here is the error.
Copy code
assert block_type, f"Block type {block_document.block_type_id} not found"
I can trace it back in the git hub files like this. The create_block_document function contains this code
Copy code
block_type = await models.block_types.read_block_type(
        session=session, block_type_id=block_document.block_type_id
    )
Which we can trace further to here
Copy code
@db_injector
async def read_block_type(
    db: PrefectDBInterface,
    session: AsyncSession,
    block_type_id: UUID,
) -> Union[BlockType, None]:
    """
    Reads a block type by id.

    Args:
        session: A database session
        block_type_id: a block_type id

    Returns:
        BlockType: an ORM block type model
    """
    return await session.get(db.BlockType, block_type_id)
So clearly, the block type UUID I got from one servers db is not the same as the new servers db. How is this possible if both servers are built with the exact same prefect image? Wouldn't both servers use the same UUID to represent, say a AWS Credentials type block? Or am I confused how this works
m
The issue you're encountering stems from the fact that block type IDs are unique to each Prefect server instance, even if they are built from the same image. This is because the UUIDs for block types are generated when the block type is first registered in the database. Therefore, they will not match across different server instances unless explicitly synchronized. To resolve this, you need to ensure that the block type is registered on the target server before you attempt to create a block document. You can do this by either: 1. Manually creating the block type on the target server using the Prefect UI or API before transferring the block document. 2. Using the Prefect API to check if the block type exists on the target server and, if not, create it before transferring the block document. Here are some relevant resources and documentation that might help you further: - Prefect Blocks Documentation - Handling Block Types in Prefect Unfortunately, there is no direct method to transfer block type IDs between different server instances due to their unique nature. You would need to handle this through your deployment or synchronization process.
upvote 1