OkunaOrg / okuna-api

🤖 The Okuna Social Network API
https://okuna.io
MIT License
242 stars 79 forks source link

Making some small changes to post causes Bad request 400 error #752

Open alsiPanda opened 3 years ago

alsiPanda commented 3 years ago

I have changed the post in PostImage to ForeignKey from one-to-one. And added a CharField called ptype, which I wanted to use for filtering based on its value. In getTopPosts, I have moved post__image from select_related to prefetch_related, and added ptype to only. I have also added ptype to curate_top_posts in jobs. On other hand, I have also added many=true wherever PostMediaSerializer is used.

I then added a query in top_post_community_query, postptypeexact="string" where string is recieved from request in view. Made relevant changes to serializer as well. This is where I am facing the problem of bad request 400 in api, and invalid model in app. If I comment out the ptype query, error dissapears and I get a list of top posts. But if I keep the query and instead comment out content_object in PostMediaSerializer, then also the 400 error dissapears, although I get error in app due to no Content object.

I tried to add the ptype field to TopPost model instead, so I could use it direct, and made all the relevant changes to jobs, and ran migration successfully. But then the scheduled job fails with Integrity error, 1364, ptype has no default even though I have added default string in the ptype field. I also tried to set null=True and null=False, but getting the same error in the failed job.

kitlu007 commented 3 years ago

@lifenautjoe any way you could help us sort this out ??

kitlu007 commented 3 years ago

@lifenautjoe anyone else whom you know could help us figure this out ?

alsiPanda commented 3 years ago

@lifenautjoe, after various trials and errors, and plenty of google search, the main issue seems to be with generic relations. For some reason, whenever the topposts contain a post without image and video, the content_object in PostMediaSerializer throws an Invalid model error. I have tried adding read_only=True to the GenericRelatedField, but to no avail. Anyway to go about solving this issue ?