add a warning when assign_mapper's __init__ initialize a non existing variable

Issue #426 resolved
Former user created an issue

I'd appreciate if the {{{init}}} method that assign_mapper adds to objects outputted some sort of warning (or even raised an exception?) when the user set a value to a variable which doesn't exist. I accidentally made a typo in my variable name and it took me quite some time to figure out what was happening since it "failed" silently. Here is what my copy now looks like.

        def __init__(self, **kwargs):
             for key, value in kwargs.items():
                 if not hasattr(self, key):
                     print "%s objects have no '%s' attribute" % (self.__class__.__name__, key)
                 setattr(self, key, value)

Of course, print is not what you'd want but I couldn't figure how to use the logger of SA for such a thing...

Comments (1)

  1. Mike Bayer repo owner

    im not a huge fan of this idea since it makes assumptions about the behavior of the class, and also you can just provide your own init method. however since this is within an extension that is already about adding commonly desired class behaviors, and its the 2nd request, I made it an optional feature, if you say assign_mapper(...., validate=True), changeset:2223.

  2. Log in to comment