Use a callable to determine persisted enum values#410
Use a callable to determine persisted enum values#410razor-1 wants to merge 4 commits intozzzeek:masterfrom
Conversation
| import datetime | ||
| import decimal | ||
| from sqlalchemy import types as sqltypes | ||
| from enum import Enum as PyEnum |
There was a problem hiding this comment.
we don't need to pull this in, see test/sql/test_types.py line 1160 where build a minimal pep435 enumerated class.
| postgresql: psycopg2>=2.7 | ||
| mysql: mysqlclient | ||
| mysql: pymysql | ||
| py27-mysql: enum34 |
|
great! so first thing, this is the core Enum type so this feature needs tests at the base level in test/sql/test_types.py -> EnumTest. When you add there, you'll find the test likely fails for Postgresql since the same change we made to the MySQL version with adding the parameter to adapt_emulated_to_native also needs to happen in sqlalchemy/dialects/postgresql/base.py -> ENUM. |
add values_callable in postgres adapt_emulated_to_native add tests to test/sql/test_types
|
Thanks for the feedback. I have attempted to address it in the latest commit. |
|
havent forgotten you, just a lot on my list and also going out of town next week. this is on my short list. |
|
great, let's test it |
|
Dear contributor - This pull request is being moved to Gerrit, at https://gerrit.sqlalchemy.org/#/c/zzzeek/sqlalchemy/+/636, where it may be tested and reviewed more closely. As such, the pull request itself is being marked "closed" or "declined", however your contribution is merely being moved to our central review system. Please register at https://gerrit.sqlalchemy.org#/register/ to send and receive comments regarding this item. |
|
it seems to have had some failures: https://jenkins.sqlalchemy.org/job/sqlalchemy_gerrit/cext=cext,db=sqlite-postgresql,pyv=py27/1310/ if you have time, at least figuring out the sqlite failures would be a start, since that DB is embedded in Python already. |
|
oh also those mysql/test_types/EnumTest should not have run for Postgresql and SQLite. that seems to be due to "from ...sql.test_types import EnumTest" in the MySQL test. I'd not include that in there. just re-state the fixture you need in your mysql-specific test suite. |
|
I think I have a fix for these things - at least for sqlite it's in better shape. I seem to get access denied errors trying to push to gerrit; is there a way to take the latest commit and add it as a new patch set? |
|
if you make a username at https://gerrit.sqlalchemy.org/ I can give you access. |
|
I'm using the same username as on github, razor-1. thank you |
|
can you add your email address to it which matches your github commit? |
|
heh. did that crash my gerrit :) gerrit is very bad from an admin perspective |
|
ugh, the dropdown is empty ? |
|
There is no dropdown - none of the above things are clickable or take any input. Reload just reloads the page and displays the same thing. |
|
try now ? |
|
you're in |
|
yes, i've added an email address now, thanks |
|
so you're in the contributors group access should work.. |
|
down to just postgres failing now. have reproduced it locally & working on a fix |
|
ok, fixed oracle. the mssql failures do not seem to be related to my changes, as far as I can tell. I also don't have easy access to mssql to run the tests. So I could use some help on that. Thank you |
Added support for :class:`.Enum` to persist the values of the enumeration, rather than the keys, when using a Python pep-435 style enumerated object. The user supplies a callable function that will return the string values to be persisted. This allows enumerations against non-string values to be value-persistable as well. Pull request courtesy Jon Snyder. Pull-request: #410 Fixes: #3906 Change-Id: Id385465d215d1e5baaad68368b168afdd846b82c

This intends to resolve https://bitbucket.org/zzzeek/sqlalchemy/issues/3906
The idea is to use
values_callableas a new kwarg to Enum. It returns the values to be used, allowing for a variety of uses, including the one mentioned in the above issue.Tests have been added as well as updates to the documentation. This is my first PR to sqlalchemy so apologies in advance for things that are out of place. Particularly I wonder if this needs to be supported in postgres as the work and tests I did were for mysql.