Great, thanks for getting me over that hurdle. I'll work on adding tests and getting a proper PR ready.
On Wed, Dec 27, 2017 at 8:07 AM, Mike Bayer <[email protected]> wrote: > MySQL's "native" type for ENUM is itself an ENUM, so needs to have > this new parameter propagated when it is told to create a "native" > implementation for a generic ENUM: > > diff --git a/lib/sqlalchemy/dialects/mysql/enumerated.py > b/lib/sqlalchemy/dialects/mysql/enumerated.py > index e67177b2f..836f14017 100644 > --- a/lib/sqlalchemy/dialects/mysql/enumerated.py > +++ b/lib/sqlalchemy/dialects/mysql/enumerated.py > @@ -114,7 +114,6 @@ class ENUM(sqltypes.NativeForEmulated, > sqltypes.Enum, _EnumeratedValues): > literals for you. This is a transitional option. > > """ > - > kw.pop('strict', None) > self._enum_init(enums, kw) > _StringType.__init__(self, length=self.length, **kw) > @@ -126,6 +125,7 @@ class ENUM(sqltypes.NativeForEmulated, > sqltypes.Enum, _EnumeratedValues): > > """ > kw.setdefault("validate_strings", impl.validate_strings) > + kw.setdefault("values_callable", impl.values_callable) > return cls(**kw) > > def _setup_for_values(self, values, objects, kw): > > On Tue, Dec 26, 2017 at 8:07 PM, Jon Snyder <[email protected]> wrote: > > Thank you very much. > > > > You can see the changes I've tried here. When I test them out, I use the > > script in this gist. When I put a breakpoint into Enum._enum_init, I see > > the correct values being populated from my function. But I'm clearly > missing > > a step here. > > > > Jon > > > > On Tue, Dec 26, 2017 at 1:38 PM, Mike Bayer <[email protected]> > > wrote: > >> > >> On Tue, Dec 26, 2017 at 12:49 PM, Jon Snyder <[email protected]> > wrote: > >> > I've started on this, by adding a new kwarg to Enum that allows > passing > >> > a > >> > function which returns the list of values. What I'm running into - > and > >> > this > >> > is just not having a good understanding of the internals - is that by > >> > the > >> > time adapt_emulated_to_native() is called, the original kwargs seem to > >> > be > >> > lost, and the new Enum that is created doesn't know anything about the > >> > one > >> > defined in the Column. It feels like it's being generated some other > >> > way, > >> > perhaps through some kind of reflection based on the definition in the > >> > db > >> > itself. Any pointers on the best way to tackle this? > >> > >> the adapt() method is probably looking for a mapping of instance > >> variable names to keyword arguments, e.g. if your keyword argument is > >> called "convert_fn", then you would have a data-member ".convert_fn" > >> that it looks for. > >> > >> None of this is required, and it all can be overridden, but if you can > >> show me an example of the type and the path to create the stack trace > >> I can answer more fully. > >> > >> > >> > >> > > >> > Thanks > >> > > >> > On Mon, Dec 4, 2017 at 1:56 PM, Mike Bayer <[email protected]> > >> > wrote: > >> >> > >> >> On Mon, Dec 4, 2017 at 12:35 PM, Jon Snyder <[email protected]> > >> >> wrote: > >> >> > Hi, > >> >> > > >> >> > The documentation and code is quite clear that it's the name, not > the > >> >> > value, > >> >> > of a PEP-435 compliant enum that is persisted to the database. > >> >> > > >> >> > My use case is that existing enums already in the db are using > >> >> > strings > >> >> > that > >> >> > are not valid python names (they contain spaces). > >> >> > > >> >> > How would the community here feel about an option to the Enum > >> >> > initializer > >> >> > that would allow using the .value of the enum for its persisted > >> >> > value? > >> >> > >> >> Ongoing discussion of this feature can be found at: > >> >> > >> >> https://bitbucket.org/zzzeek/sqlalchemy/issues/3906 > >> >> > >> >> the reservation with persistence of "value" is that the datatype of > >> >> the values of an Enum, while they may be strings, can be any datatype > >> >> at all including integers or custom objects, whereas the keys are > >> >> always strings. The means of deriving the Enum value as a string > >> >> should be pluggable (e.g. pass a function). > >> >> > >> >> > >> >> > > >> >> > Thank you > >> >> > > >> >> > -- > >> >> > SQLAlchemy - > >> >> > The Python SQL Toolkit and Object Relational Mapper > >> >> > > >> >> > http://www.sqlalchemy.org/ > >> >> > > >> >> > To post example code, please provide an MCVE: Minimal, Complete, > and > >> >> > Verifiable Example. See http://stackoverflow.com/help/mcve for a > full > >> >> > description. > >> >> > --- > >> >> > You received this message because you are subscribed to the Google > >> >> > Groups > >> >> > "sqlalchemy" group. > >> >> > To unsubscribe from this group and stop receiving emails from it, > >> >> > send > >> >> > an > >> >> > email to [email protected]. > >> >> > To post to this group, send email to [email protected]. > >> >> > Visit this group at https://groups.google.com/group/sqlalchemy. > >> >> > For more options, visit https://groups.google.com/d/optout. > >> >> > >> >> -- > >> >> SQLAlchemy - > >> >> The Python SQL Toolkit and Object Relational Mapper > >> >> > >> >> http://www.sqlalchemy.org/ > >> >> > >> >> To post example code, please provide an MCVE: Minimal, Complete, and > >> >> Verifiable Example. See http://stackoverflow.com/help/mcve for a > full > >> >> description. > >> >> --- > >> >> You received this message because you are subscribed to a topic in > the > >> >> Google Groups "sqlalchemy" group. > >> >> To unsubscribe from this topic, visit > >> >> https://groups.google.com/d/topic/sqlalchemy/_dgcR9lqY94/unsubscribe > . > >> >> To unsubscribe from this group and all its topics, send an email to > >> >> [email protected]. > >> >> To post to this group, send email to [email protected]. > >> >> Visit this group at https://groups.google.com/group/sqlalchemy. > >> >> For more options, visit https://groups.google.com/d/optout. > >> > > >> > > >> > -- > >> > SQLAlchemy - > >> > The Python SQL Toolkit and Object Relational Mapper > >> > > >> > http://www.sqlalchemy.org/ > >> > > >> > To post example code, please provide an MCVE: Minimal, Complete, and > >> > Verifiable Example. See http://stackoverflow.com/help/mcve for a full > >> > description. > >> > --- > >> > You received this message because you are subscribed to the Google > >> > Groups > >> > "sqlalchemy" group. > >> > To unsubscribe from this group and stop receiving emails from it, send > >> > an > >> > email to [email protected]. > >> > To post to this group, send email to [email protected]. > >> > Visit this group at https://groups.google.com/group/sqlalchemy. > >> > For more options, visit https://groups.google.com/d/optout. > >> > >> -- > >> SQLAlchemy - > >> The Python SQL Toolkit and Object Relational Mapper > >> > >> http://www.sqlalchemy.org/ > >> > >> To post example code, please provide an MCVE: Minimal, Complete, and > >> Verifiable Example. See http://stackoverflow.com/help/mcve for a full > >> description. > >> --- > >> You received this message because you are subscribed to a topic in the > >> Google Groups "sqlalchemy" group. > >> To unsubscribe from this topic, visit > >> https://groups.google.com/d/topic/sqlalchemy/_dgcR9lqY94/unsubscribe. > >> To unsubscribe from this group and all its topics, send an email to > >> [email protected]. > >> To post to this group, send email to [email protected]. > >> Visit this group at https://groups.google.com/group/sqlalchemy. > >> For more options, visit https://groups.google.com/d/optout. > > > > > > -- > > SQLAlchemy - > > The Python SQL Toolkit and Object Relational Mapper > > > > http://www.sqlalchemy.org/ > > > > To post example code, please provide an MCVE: Minimal, Complete, and > > Verifiable Example. See http://stackoverflow.com/help/mcve for a full > > description. > > --- > > You received this message because you are subscribed to the Google Groups > > "sqlalchemy" group. > > To unsubscribe from this group and stop receiving emails from it, send an > > email to [email protected]. > > To post to this group, send email to [email protected]. > > Visit this group at https://groups.google.com/group/sqlalchemy. > > For more options, visit https://groups.google.com/d/optout. > > -- > SQLAlchemy - > The Python SQL Toolkit and Object Relational Mapper > > http://www.sqlalchemy.org/ > > To post example code, please provide an MCVE: Minimal, Complete, and > Verifiable Example. See http://stackoverflow.com/help/mcve for a full > description. > --- > You received this message because you are subscribed to a topic in the > Google Groups "sqlalchemy" group. > To unsubscribe from this topic, visit https://groups.google.com/d/ > topic/sqlalchemy/_dgcR9lqY94/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/sqlalchemy. > For more options, visit https://groups.google.com/d/optout. > -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
