document / provide clear path for custom SQL constructs that support autocommit

Issue #2230 resolved
Former user created an issue

Following advice on http://www.sqlalchemy.org/docs/core/compiler.html I create a custom InsertFromSelect element. Unfortunately it seems that it doesn't make the actual insert, even though the SQL generated looks fine.

From a shallow look it seems no COMMIT-statement is issued when InsertFromSelect is executed.

It works fine, if instead of subclassing Executable, ClauseElement, we subclass UpdateBase.

See attached unittest-script for the code to recreate and "resolve" the problem.

Comments (4)

  1. Mike Bayer repo owner

    since you're using connectionless execution with no transaction you need to apply autocommit to the construct in order for it to autocommit.

    class InsertFromSelect(Executable, ClauseElement):
        _execution_options = \
            Executable._execution_options.union({'autocommit': True})
    

    or:

    insert = insert.execution_options(autocommit=True)
    

    the path here should be clearer somehow, either AutocommitExecutable, or something like that.

  2. Mike Bayer repo owner

    we've had the _execution_options workaround documented for quite some time now so that's what we'll keep for now.

  3. Log in to comment