Skip to content

Cannot deploy multiple flows that use the same proto-plus Message class with Prefect 3 #17150

@jmesterh

Description

@jmesterh

Bug summary

We're trying to update to Prefect 3 (from 2), when running prefect deploy --all, if more than one deployment imports the same class with a base class of "proto.Message", the second deployment fails with TypeError: Couldn't build proto file into descriptor pool: duplicate symbol '_default_package.<Class>'.

Calling prefect deploy twice (once for each deployment) is a possible work-around, but this all works fine in Prefect 2.x, using the same version of proto-plus.

protobuf-1.py:

from prefect import flow
from .message import FooMessage

@flow
async def flow_1():
    pass

protobuf-2.py:

from prefect import flow
from .message import FooMessage

@flow
async def flow_2():
    pass

message.py:

import proto

class FooMessage(proto.Message):
    foo = proto.Field(proto.STRING, number=1)

deployment.yaml:

deployments:
  - name: flow 1
    entrypoint: protobuf-1.py:flow_1
    work_pool:
      name: process-pool
  - name: flow 2
    entrypoint: protobuf-2.py:flow_2
    work_pool:
      name: process-pool
$ prefect --no-prompt deploy  --all
Deploying flows with selected deployment configurations...
(flow-1 deploys successfully) 
│ Deploying flow 2                                                                                                                                                 │
Traceback (most recent call last):
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "protobuf-2.py", line 4, in <module>
    from .message import FooMessage
  File "message.py", line 4, in <module>
    class FooMessage(proto.Message):
  File "message.py", line 279, in __new__
    file_info.generate_file_pb(new_class=cls, fallback_salt=full_name)
  File ".venv/lib/python3.11/site-packages/proto/_file_info.py", line 104, in generate_file_pb
    pool.Add(self.descriptor)
TypeError: Couldn't build proto file into descriptor pool: duplicate symbol '_default_package.FooMessage'

Version info

Version:             3.2.2
API version:         0.8.4
Python version:      3.11.11
Git commit:          d982c69a
Built:               Thu, Feb 13, 2025 10:53 AM
OS/Arch:             linux/aarch64
Profile:             ephemeral
Server type:         server
Pydantic version:    2.9.2
Integrations:
  prefect-sqlalchemy: 0.5.2
  prefect-dask:      0.3.2
  prefect-docker:    0.6.2
  prefect-dbt:       0.6.6
  prefect-gcp:       0.6.2
  prefect-slack:     0.3.1
  prefect-shell:     0.3.1

protobuf==5.29.3
proto-plus==1.26.0

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions