Unable to edit user account because of slug
I was trying to edit the user account from the front-end in Coopstarter which was working well before djangoldp_account update. Detail of the request:
curl 'http://localhost:8000/users/victorinox/' \
-X PUT -H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:69.0) Gecko/20100101 Firefox/69.0' \
-H 'Accept: */*' -H 'Accept-Language: en-US,en;q=0.5' \
--compressed \
-H 'Referer: http://localhost:9000/en/mentor-dashboard/mentor-account-edit' \
-H 'Content-Type: application/ld+json' -H 'Origin: http://localhost:9000' -H 'Connection: keep-alive' -H 'Cookie: csrftoken=L67VNTuzwpnTOBvjW16Jas3cIPIgbIWuR7zq4yvg90rdxEIvs3BYU5sfKvkm8r02; sessionid=fjrwu42lxasvg34nutm5vwhzlt1xm02k; refreshToken=def5020053f33ac7a7a9515c594b8b44620bad0a61a403b5d03e23235cf7615efa8247a3e096e727309c94e2c8ae1fd9b36ef39479b9eecb753fae8ce053d17ac125e96eb45f51ad0a403c941caf1cfd7d7609ada323410482224605104a0afae4a53915d1f5edbecff8160e66574570d6a0c1423de47a22786b52a2c06b2a342f627fbf197e5fd40c732a37aec7392e5039ad52225955b1eafc11b7d14d561ca73bdc15e47a57dc39ac60e3eca38f2d042064cf5121b572ac9ee30f4b2b999d564d1afdf57ccb16134fe9a131540ff67968e2e28f80dfcc284b765ca5c9d2bc7b07a5449e6630710f8d17408781a388bc565e6c3f3eb9f7b9fc38bddd7159744c1d72583fe68f487ea7ef3d81b508798b1797ff94122effc238010effb6caf0c2611ca157462a7bf03c03beba9dded38c15c49267bad5315b60ac33101e8677f1669ede16c8d97dc1bb7c4e1b9cfeb1c14cf06544b11760276aea27eb542bc9b0be' \
-H 'Pragma: no-cache' \
-H 'Cache-Control: no-cache' \
--data '{"username":"victorinox","last_name":"Wikiki","first_name":"Wiko","mentorProfile":{"organisation":{"@id":"http://localhost:8000/organisations/3/"},"phone":"02930239093","languages":[{"@id":"http://localhost:8000/languages/2/"}],"fields":[{"@id":"http://localhost:8000/fields/8/"},{"@id":"http://localhost:8000/fields/9/"}],"headline":"Lead web totoro","city":"Totoro","country":{"@id":"http://localhost:8000/countrys/1/"},"biography":"oazndoazn","skills":"zoainaoidnanoid oizdnzaond","linkedin":"https://linkedin.com/in/benoitalessandroni","twitter":"https://twitter.com/balessan"},"header_about_you":"","account":{"picture":"http://localhost:8000/media/profile_g3MRers.jpg"},"header_social_media":"","@id":"http://localhost:8000/users/victorinox/","@context":{"@vocab":"http://happy-dev.fr/owl/#","rdf":"http://www.w3.org/1999/02/22-rdf-syntax-ns#","rdfs":"http://www.w3.org/2000/01/rdf-schema#","ldp":"http://www.w3.org/ns/ldp#","foaf":"http://xmlns.com/foaf/0.1/","name":"rdfs:label","acl":"http://www.w3.org/ns/auth/acl#","permissions":"acl:accessControl","mode":"acl:mode","entrepreneurProfile":"http://happy-dev.fr/owl/#entrepreneur_profile","mentorProfile":"http://happy-dev.fr/owl/#mentor_profile","account":"http://happy-dev.fr/owl/#account"}}'
After update, the response of the POST request was of type
{
"account":{
"slug":[
"This field is required."
]
},
"@context":"https://cdn.happy-dev.fr/owl/hdcontext.jsonld"
}
I tried to add the account.slug field as a hidden one, as we are doing for the username, but then it failed on the unicity constraint of this field:
{
"account":{
"slug":[
"account with this slug already exists."
]
},
"@context":"https://cdn.happy-dev.fr/owl/hdcontext.jsonld"
}
What I temporary did to allow those editions (because I had to deploy a production instance) is to patch the models.py file in an ugly way:
class Account(Model):
user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
- slug = models.SlugField(unique=True)
+ slug = models.SlugField(unique=True, blank=True, null=True)
Is that normal behaviour ?