Thank you very much. You can see the changes I've tried here <https://github.com/zzzeek/sqlalchemy/compare/master...razor-1:custom-enum-values>. When I test them out, I use the script in this <https://gist.github.com/razor-1/1ff0adfb17071acf1f810dc286154a8b> 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.
