Skip to content

migrate from dill to cloudpickle for advanced serialization #7870

Closed

Description

@jrwalk

Description

Usage of dill for optional serialization in PythonVirtualenvOperator may be replaced with cloudpickle as its serialization library. This should be a mostly drop-in replacement.

Use case / motivation

Currently, the PythonVirtualenvOperator optionally uses dill in place of stock pickle to serialize advanced types. However, most major distributed compute frameworks have opted to shift to cloudpickle, meaning using dill for Airflow can introduce redundant dependencies for calling out to other distributed compute (e.g., farming compute-heavy tasks out to a remote dask cluster), and can interfere with serialization of tasks for those tools.

Since both dill and cloudpickle are largely drop-in replacements for pickle, the migration should be fairly minor.

Related Issues

kubeflow/pipelines#1387

dask/distributed#3606

piskvorky/gensim#558 (comment)

uqfoundation/multiprocess#22 (comment)

Activity

  1. added
    kind:feature
    on Mar 25, 2020
  2. boring-cyborg commented on Mar 25, 2020

    @boring-cyborg

    Thanks for opening your first issue here! Be sure to follow the issue template!

  3. ashb commented on Mar 26, 2020

    @ashb
    Member

    Is it worth making the pickle module a config setting, or just always using cloudpickle instead?

  4. jrwalk commented on Mar 27, 2020

    @jrwalk
    Author

    so dill is optional to use (set by a flag in the PythonVirtualenvOperator) but is always imported and treated as a required dependency for Airflow, right? Keeping that pattern it should be super easy to cut over to cloudpickle.

    I'd generally advocate for allowing fewer dependencies though, so it could be nice to make cloudpickle a proper extra-dependency and put some checks around the import. That would let people keep minimal environments if they choose/need to. I've also run into situations where it wasn't being used (no virtualenv operators in my dag) but because it was imported dill was still getting captured by serializers like cloudpickle since they scoop up a fair amount of runtime environment information.

  5. jrwalk commented on Mar 27, 2020

    @jrwalk
    Author

    either way it would probably also necessitate reworking some of the tests, since (for example) cloudpickle could conceivably serialize lambda functions for the python_callable inputs

  6. added this to the Airflow 2.3.0 milestone on Dec 30, 2021
  7. removed this from the Airflow 2.3.0 milestone on Apr 22, 2022
  8. sumeshpremraj commented on Jul 12, 2023

    @sumeshpremraj
    Contributor

    Hi @jrwalk, can I work on this?
    dill and cloudpickle seem to be fairly similar, is there anything else I should consider (except for the tests your mentioned)?

  9. potiuk commented on Jul 12, 2023

    @potiuk
    Member

    Assigned you. The issue is pretty old - we also have ExternalPythonOperator using same approach now. I think just focusing on tests for those might be enough

  10. removed their assignment
    on Jul 26, 2023
  11. Felix-neko commented on Nov 8, 2023

    @Felix-neko

    #35529 -- maybe using cloudpickle could cure this problem?

  12. potiuk commented on Nov 8, 2023

    @potiuk
    Member

    #35529 -- maybe using cloudpickle could cure this problem?

    If you would like to take a stab on it and attempt to try it - fee free to verify that hypothesis @Felix-neko - PRs are always most welcome.

  13. Felix-neko commented on Nov 8, 2023

    @Felix-neko

    #35529 -- maybe using cloudpickle could cure this problem?

    If you would like to take a stab on it and attempt to try it - fee free to verify that hypothesis @Felix-neko - PRs are always most welcome.

    Heh, it looks like you're overestimating my power (and my current knowledge in cloudpickle and airflow)
    ; )

  14. Taragolis commented on Nov 8, 2023

    @Taragolis
    Contributor

    It might help. There is also limitations for cloudpickle exists:

    Cloudpickle can only be used to send objects between the exact same version of Python.

  15. Felix-neko commented on Nov 8, 2023

    @Felix-neko

    Cloudpickle can only be used to send objects between the exact same version of Python.

    That won't be a big problem. Especially if simple dill will still be supported.

  16. VladaZakharova commented on Mar 21, 2024

    @VladaZakharova
    Contributor

    @sumeshpremraj
    Hi there! May I ask how is the progress going on this issue?

  17. added
    airflow3.0:candidate
    airflow3.0:breaking
    on Jul 18, 2024
  18. gyli commented on Jul 20, 2024

    @gyli
    Collaborator

    With #39270 completed, argument serializer was added to support choosing from serializers. Looks like this issue can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    airflow3.0:breakingairflow3.0:candidatearea:serializationgood first issuekind:feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions