Support uuid input field
See original GitHub issueHi 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:
-
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 ofBookInput
. -
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:
- Created 6 years ago
- Reactions:1
- Comments:9
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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.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 produceFalse
.I don’t want to replace the
dashes
from theargs.get('uuid')
or do extra redundant work like load object from DB.Do you know why
args.get('uuid')
containsdashes
? Because theuuid
field returns from the graphql query containsdashes
.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.