djongo icon indicating copy to clipboard operation
djongo copied to clipboard

int() argument must be a string, a bytes-like object or a number, not 'ObjectId'

Open iambhushan6 opened this issue 3 years ago • 3 comments

id is not autogenerated in mongodb when given id in serializer it throws this error

Python script

<copy and paste code here>
class Order(models.Model):

    owner = models.ForeignKey(to= User, on_delete= models.CASCADE)
    fromlocation = models.CharField(max_length=256)
    tolocation = models.CharField(max_length=256)
    vehicletype = models.CharField(max_length=256)
    vehicleroof = models.CharField(max_length=16)
    partialweight = models.IntegerField()
    loadtype = models.CharField(max_length=16)
    date = models.DateField()
    time = models.TimeField()
    status = models.CharField(max_length= 16) 

Traceback

TypeError at /business/orders/ int() argument must be a string, a bytes-like object or a number, not 'ObjectId'

iambhushan6 avatar Sep 21 '21 11:09 iambhushan6

i've had the same issue, current workaround i've found is to:

  • install uuid
  • add this field to the model id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)

pokorny-martin avatar Dec 28 '21 08:12 pokorny-martin

uuid is builtin - no need to insall anything

im-n1 avatar Jan 13 '22 15:01 im-n1

@pokorny-martin that's a dirty workaround (creates id field in Mongo next to already existing _id one) but I can confirm it works.

However this bug needs a proper solution.

im-n1 avatar Jan 14 '22 12:01 im-n1