support "regardless of cascade settings" mode for cascade_iterator

Issue #3498 resolved
jvanasco created an issue

http://docs.sqlalchemy.org/en/rel_1_0/orm/mapping_api.html?highlight=cascade_iterator#sqlalchemy.orm.mapper.Mapper.cascade_iterator

Using this code, I would expect to the cascade for "all" contain all objects instance_state.mapper.cascade_iterator('all', instance_state)

instead, I see an empty list.

using the defaults, i see what I want instance_state.mapper.cascade_iterator('save-update', instance_state) instance_state.mapper.cascade_iterator('merge', instance_state)

I think "all" is filtering for rules that match an explicit all cascade, not "all cascades"

perhaps a new argument, such as "all_rules" is needed?

The docs on the attribute could be better. It seems this returns a generator, of which every element is a tuple in the following form:

  • [0] orm object
  • [1] Mapper of [0]
  • [2] InstanceState of [0]
  • [3] dict of [0]

Comments (10)

  1. Mike Bayer repo owner

    I knew you were going to want this, but you don't want "all", "all" means to specify all of save-update, merge, expunge, etc., which makes no sense for this method, as this method operates upon an existing cascade. you want an option here that says the operation should take place regardless of the cascade setting on any relationships, you want all the objects no matter what. right? this method is only marginally public API so tailoring it for people's use is a new thing.

  2. jvanasco reporter

    Yeah, exactly.

    The current behavior makes sense -- that handles an explicit "all" setting. There's just no way to get the implicit 'all' of "each and every item that this somehow cascades to" (well there is, select a few options and pop the results into a set).

  3. Mike Bayer repo owner
    • changed milestone to 1.2

    hoping you're working around this for now, this is lower on my priority though a PR with tests could help.

  4. Mike Bayer repo owner
    • add a new FAQ recipe for "walk all objects", replacing the need to use mapper.cascade_iterator() for this purpose as it was not really designed for that use case. Add docs to cascade_iterator() pointing to the recipe. fixes #3498

    → <<cset 03797b78475b>>

  5. Log in to comment