Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UUIDs cannot be queried using get as primary key

See original GitHub issue

Recently, I started using ormar instead of tortoise-orm in my projects, but have encountered a strange problem, if I use uuid as the primary key of a model, I can’t match the data when using get query.


class MainMeta(ormar.ModelMeta):
    metadata = metadata
    database = database

class UserModel(ormar.Model):

    class Meta(MainMeta):
        tablename = "usermodel"

    id: ormar.UUID(primary_key=True)
    username = ormar.String(index=True, unique=True, null=False, max_length=255)
    email = ormar.String(index=True, unique=True, nullable=False, max_length=255)
    hashed_password = ormar.String(null=False, max_length=255)
    is_active = ormar.Boolean(default=True, nullable=False)
    is_superuser = ormar.Boolean(default=False, nullable=False)

user = await UserModel.objects.first()
await UserModel.objects.get( # raise NoMatch
await UserModel.objects.get(username=user.username) # Match user

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

hidariscommented, Nov 27, 2020

Screenshot from 2020-11-28 03-20-18 This is the table structure corresponding to the usermodel

hidariscommented, Nov 28, 2020

Problem solved, thank you for such a quick response and fix!

Read more comments on GitHub >

github_iconTop Results From Across the Web

UUID or GUID as Primary Keys? Be Careful! | by Tom Harrison
Reasons UUIDs May Not be Good · Don't be naive · UUIDs are a pain · Planning for real scaling · Primary keys...
Read more >
Be Careful with UUID or GUID as Primary Keys - Hacker News
Badly chosen surrogate keys or time-series clustering can lead to performance problems that are just as severe depending on your access patterns ...
Read more >
Cannot use UUID as a primary key: Uuid: diesel::Expression is ...
I found some old post that suggested that the field might be nullable but id is the PRIMARY KEY in my table up.sql,...
Read more >
Auto-generated primary keys: UUID, serial or identity column?
This article explores the old question what to use for autogenerated primary keys: UUID, serial or identity column?
Read more >
UUIDs are Popular, but Bad for Performance — Let's Discuss
The tables now use integers as primary keys. This mapping removes nearly all the scalability concerns of using UUID values.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found