On 05/19/2017 04:53 PM, Colton Allen wrote:
I get some issues when appending a model to an "orm.relationship" (UnorderableType error). Which is annoying but can be worked around.

that doesn't sound like something in SQLAlchemy


I also use SQLAlchemy-Continuum which seems to have issues with retrieving "orm.relationship"s. It will attempt to query using the shortuuid type without transforming it to the uuid type.

this sounds like the type does not have proper expression behavior. The right-hand side of a comparison should be coerced into your type, this depends on how the UUID type was constructed in sqlalchemy-utils.

 Obviously this
is third-party stuff but I am curious how I could go about creating my own relationship mapper. Something that would be resilient enough to understand shortuuids need to be converted to UUIDs.

adding your custom type to an MCVE that illustrates the query that is failing would make it easy to see where it's going wrong


I thought there might be something obviously wrong with my implementation (since its my first one) which I why I lead off with that.

I'm not sure that sqlalchemy-utils follows all the changes we've made to the typing system over the years so it may have behaviors that no longer work, namely the type coercion thing changed some years back.





On Friday, May 19, 2017 at 6:19:45 AM UTC-7, Mike Bayer wrote:

    looks fine to me?   what did you have in mind?



    On 05/18/2017 11:29 PM, Colton Allen wrote:
     > I want to make my UUID's prettier so I've gone about implementing a
     > ShortUUID column based on the shortuuid library[1].  The idea is to
     > store the primary key as a UUID type in postgres (since its
    optimized
     > for that) and transform the UUID to a shortuuid for presentation and
     > querying.  This is my first attempt at implementing it.  It has some
     > short comings.
     >
     > I was wondering if you had any advice for fully baking the
     > implementation.  I've pasted the code I have so far.
     >
     >
     > from sqlalchemy_utils.types.uuid import UUIDType
     >
     > import uuid
     > import shortuuid
     >
     >
     > def _decode_shortuuid(value):
     >      try:
     >          return shortuuid.decode(value)
     >      except ValueError:
     >          return None
     >
     >
     > def _encode_shortuuid(value):
     >      try:
     >          if value is None:
     >              return None
     >          return shortuuid.encode(value)
     >      except KeyError:
     >          return None
     >
     >
     > class ShortUUID(UUIDType):
     >      """Converts UUIDs to ShortUUIDs for readability's sake."""
     >
     >      def process_bind_param(self, value, dialect):
     >          """Process a ShortUUID to a UUID."""
     >          if value is None:
     >              return value
     >
     >          if type(value) != uuid.UUID:
     >              value = _decode_shortuuid(value)
     >          return super().process_bind_param(value, dialect)
     >
     >      def process_result_value(self, value, dialect):
     >          """Return a ShortUUID encoded UUID."""
     >          value = super().process_result_value(value, dialect)
     >          return _encode_shortuuid(value)
     >
     >
     > 1. https://github.com/skorokithakis/shortuuid
    <https://github.com/skorokithakis/shortuuid>
     >
     > --
     > 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
    <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 sqlalchemy+...@googlegroups.com <javascript:>
     > <mailto:sqlalchemy+unsubscr...@googlegroups.com <javascript:>>.
     > To post to this group, send email to sqlal...@googlegroups.com
    <javascript:>
     > <mailto:sqlal...@googlegroups.com <javascript:>>.
     > Visit this group at https://groups.google.com/group/sqlalchemy
    <https://groups.google.com/group/sqlalchemy>.
     > For more options, visit https://groups.google.com/d/optout
    <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 sqlalchemy+unsubscr...@googlegroups.com <mailto:sqlalchemy+unsubscr...@googlegroups.com>. To post to this group, send email to sqlalchemy@googlegroups.com <mailto:sqlalchemy@googlegroups.com>.
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to