Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

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

Open
alsiPanda opened this issue Feb 18, 2021 · 3 comments
Open

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

alsiPanda opened this issue Feb 18, 2021 · 3 comments

Comments

@alsiPanda
Copy link

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, post__ptype__exact="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
Copy link

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

@kitlu007
Copy link

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

@alsiPanda
Copy link
Author

alsiPanda commented Feb 19, 2021

@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 ?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants