question-mark
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.

Support uuid input field

See original GitHub issue

Hi there,

I have the model book:

class User(models.Model):
    id = models.UUIDField(default=uuid.uuid4, primary_key=True)
    ... 

class Book(models.Model):
    id = models.UUIDField(default=uuid.uuid4, primary_key=True)
   owner = models.foreignFeild(User)
    ...

class UserType(DjangoObjectType):
   model = User

class BookType(DjangoObjectType):
   model = Book

class BookInput(InputObjectType):
    id = graphene.String() # Could you support graphene.Uuid() 
    owner_id = graphene.String() # Could you support graphene.Uuid() 

class ChangeBookOwner(graphene.Mutation):
    class Input:
        book_input = graphene.Field(BookInput, required=True)
    
    @staticmethod
    def mutate(root, args, context, info):
       id = args.get('book_input').get('id')
       book = Book.objects.get(pk=id)
       if book.owner_id == args.get('book_input').get('owner_id'): # this is always false
          # notify to the new owner

The book.owner_id == args.get('book_input').get('owner_id') is always false because:

  1. when querying the BookType it returns the owner_id with aa-bb-cc-dd format which includes dash symbol and I use this owner_id to set the owner_id of BookInput.

  2. book.owner_id is always in aabbccdd format which doesn’t include dash symbol.

Could you help me figure out the best way to deal with it without hacks?

Thanks a lot.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:9

github_iconTop GitHub Comments

1reaction
dopeboycommented, May 8, 2019

@zbyte64, is correct. So long as you’ve defined your argument to be of type graphene.UUID(), that equality test mentioned by @quytang will work. Closing this down.

1reaction
quytangcommented, Aug 9, 2017

The problem is the comparison, not loading from DB.

Have you ever tried the comparision args.get('uuid') === user.uuid. Let do that and you will see the comparison produce False.

I don’t want to replace the dashes from the args.get('uuid') or do extra redundant work like load object from DB.

Do you know why args.get('uuid') contains dashes? Because the uuid field returns from the graphql query contains dashes. user.uuid loaded from DB has no dashes. I already mentioned them in the description of the issue.

Additionally, user.uuid loaded from DB is instance of uuid.UUID, but args.get(‘uuid’) is instance of String. So what I asked for is to have graphene.Uuid() field for the ideal solution.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Generete Unique Id and pass into text field - Stack Overflow
I am new to php and would like some help on solving a problem I am having. I have a form that has...
Read more >
UuidAPI - KeystoneJS
The Uuid field type stores Universally Unique Identifiers (UUIDs). UUIDs are 128-bit numbers but they're often represented in hexadecimal using ...
Read more >
Using the UUID data type - Oracle Help Center
In Oracle NoSQL, UUID values are represented by the UUID data type. ... Input format: The input string must conform to the format...
Read more >
uuid — UUID objects according to RFC 4122 ... - Python Docs
Source code: Lib/uuid.py This module provides immutable UUID objects (the UUID class) and the functions uuid1(), uuid3(), uuid4(), uuid5() for generating ...
Read more >
uuid validator - FormValidation
Supports popular frameworks including Bootstrap, Zurb Foundation, Pure, Semantic, UIKit, Bulma, ... Validate an UUID. Options. Using with form field.
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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found