This has often caught me out. And I think so long as there's an option to disable the auto-registration (for power users) this sounds like a great feature.
Hash On 27 April 2022 09:49:50 BST, Malthe <[email protected]> wrote: >DAGs must be registered at the module top-level. During dagbag >processing we have: > > top_level_dags = ((o, m) for m in mods for o in >m.__dict__.values() if isinstance(o, DAG)) > >It makes sense of course – we can't have DAGs floating in space, they >need an anchor. > >Or do they? > >It would be entirely possible for the DAG constructor to register >itself with some global registry, obviating for the follow pattern: > >with DAG(...) as dag: > ... > >I think most users would prefer: > >with DAG(...): > ... > >Since there is generally speaking no need for the alias. > >Downsides? You have less control of what DAGs are made available – but >really, does it make sense to create a DAG object only to drop it >immediately after? > >I volunteer to implement this if there's a positive feedback. > >Cheers
