0

For reference, I've been primarily using these 2 resources

AttributeError: 'UUID' object has no attribute 'replace' when using backend-agnostic GUID type https://websauna.org/docs/narrative/modelling/models.html#uuid-primary-keys

which seem to show that the issue is resolved though I can't seem to get it to work on my end.

My error is the same as in the SO post above but for thoroughness here it is:

 File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/uuid.py", line 137, in __init__
    hex = hex.replace('urn:', '').replace('uuid:', '')
AttributeError: 'UUID' object has no attribute 'replace'

My model is as follows:

import sqlalchemy
from .base import Base
from sqlalchemy import Column
from sqlalchemy.dialects.postgresql import UUID

class ModelItem(Base):
    __tablename__ = 'item'

    id = Column(UUID(as_uuid=True),
            server_default=sqlalchemy.text("uuid_generate_v4()"), 
            primary_key=True, 
            nullable=False)

Are there other known work arounds?

Sam L.
  • 43
  • 1
  • 8
  • Try to convert the hex variable into a string and then perform the replace task. – Saurav Panda Nov 28 '19 at 05:50
  • How would I go about that? It's done within the library so would I go into the module and switch up code there? That seems dangerous – Sam L. Nov 28 '19 at 06:17
  • How are you triggering this error? I can't reproduce it from your code using sqlalchemy 1.3.10, psycopg2 2.8.4, python 3.8. – snakecharmerb Nov 30 '19 at 10:27

1 Answers1

0

hex = str(hex).replace('urn:', '').replace('uuid:', '')

Saurav Panda
  • 558
  • 5
  • 12
  • What level of concern should I have for this causing errors in the future? It looks fine to do at first glance but not sure about what consequences it'll actually have – Sam L. Nov 28 '19 at 07:02
  • I feel it won't have any bad consequences as we are just typecasting the variable and storing it to a new instance of that same variable. We are not modifying the actual function or anything here. To be more safe, store output is a new variable like: new_hex = str(hex).replace('urn:', '').replace('uuid:', '') – Saurav Panda Nov 28 '19 at 07:34