Skip to content

Instantly share code, notes, and snippets.

@protosam
Last active July 11, 2021 21:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save protosam/bf4a0e985058c34253516b66a74fd215 to your computer and use it in GitHub Desktop.
Save protosam/bf4a0e985058c34253516b66a74fd215 to your computer and use it in GitHub Desktop.

I don't understand why livepony.py works and deadpony.py results in error. This shouldn't matter.

$ python3 deadpony.py 
Traceback (most recent call last):
  File "deadpony.py", line 8, in <module>
    class AuthToken(db.Entity):
  File "deadpony.py", line 10, in AuthToken
    user_uuid     = orm.Required(uuid.UUID)
AttributeError: 'PrimaryKey' object has no attribute 'UUID'

Update

Wow, it's amazing how bad of a language python is. You can reference AuthToken.uuid outside of methods without referencing self or anything. This is dumb.

#!/usr/bin/env python3
from pony import orm
import uuid
db = orm.Database()
db.bind(provider='sqlite', filename="database.sqlite", create_db=True)
class AuthToken(db.Entity):
uuid = orm.PrimaryKey(uuid.UUID)
user_uuid = orm.Required(uuid.UUID) # uuid is no longer referencing the library, but the uuid value above it.
db.generate_mapping(create_tables=True)
#!/usr/bin/env python3
from pony import orm
import uuid
db = orm.Database()
db.bind(provider='sqlite', filename="database.sqlite", create_db=True)
class AuthToken(db.Entity):
user_uuid = orm.Required(uuid.UUID)
uuid = orm.PrimaryKey(uuid.UUID)
db.generate_mapping(create_tables=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment