multi-valued insert invokes default for same column many times

Issue #4075 resolved
Mike Bayer repo owner created an issue

this case can't be handled without adding additional context:

from sqlalchemy import *

m = MetaData()


def my_default(context):
    print "Called!  What index are we? current params: %s" % context.current_parameters
    return 0

t = Table('t', m, Column('x', Integer), Column('y', Integer, default=my_default))

e = create_engine("mysql://scott:tiger@localhost/test")


m.create_all(e)

e.execute(t.insert().values([{"x": 5}, {"x": 6}, {"x": 7}]))
Called!  What index are we? current params: {u'y_m2': None, u'y_m1': None, u'x_m0': 5, u'x_m1': 6, u'x_m2': 7, 'y': None}
Called!  What index are we? current params: {u'y_m2': None, u'y_m1': None, u'x_m0': 5, u'x_m1': 6, u'x_m2': 7, 'y': 0}
Called!  What index are we? current params: {u'y_m2': None, u'y_m1': 0, u'x_m0': 5, u'x_m1': 6, u'x_m2': 7, 'y': 0}

will add new method.

Comments (2)

  1. Mike Bayer reporter

    Add multivalued insert context for defaults

    Added a new method :class:.DefaultExecutionContext.current_parameters which is used within a function-based default value generator in order to retrieve the current parameters being passed to the statement. The new function differs from the .current_parameters attribute in that it also provides for optional grouping of parameters that correspond to a multi-valued "insert" construct. Previously it was not possible to identify the subset of parameters that were relevant to the function call.

    Change-Id: I6894c7b4a2bce3e83c3ade8af0e5b2f8df37b785 Fixes: #4075

    → <<cset aed2324b4de3>>

  2. Log in to comment