Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deleting a feature image becomes "" instead of null and breaks filter query #9085

Closed
NistorCristian opened this issue Oct 3, 2017 · 5 comments · Fixed by #9432
Closed

Deleting a feature image becomes "" instead of null and breaks filter query #9085

NistorCristian opened this issue Oct 3, 2017 · 5 comments · Fixed by #9432
Assignees
Labels
bug [triage] something behaving unexpectedly server / core Issues relating to the server or core of Ghost

Comments

@NistorCristian
Copy link

Hello,
I was trying to get all posts that have set a featured image.

{{#get "posts" limit="5" filter="id:-{{id}}+feature_image:-null"}}

First ... I imported all the content from another blog. And the rule feature_image:-null was ignored.
I created a new post without the featured image and the filter works. It doesn't get the post. Then I set a featured image, saved the post, removed the featured image and saved again the post. Now the rule feature_image:-null gets ignored and the query selects the new post, even if it doesn't have an image.

So something is set in db instead of null after the featured image gets removed.

I exported the json and checked the feature_image value.
When I created the post the value was "feature_image": null and it was good, but after I set the image and removed it, it became "feature_image": "".

This breaks the filter query.

P.S. In this url: https://api.ghost.org/docs/filter ... it says filter="featured:true,image:-null" and should, probably, be filter="featured:true,feature_image:-null" and images:-null shoud be feature_image:-null

  • Ghost Version: 1.10.0
@kirrg001 kirrg001 self-assigned this Oct 3, 2017
@kirrg001
Copy link
Contributor

kirrg001 commented Oct 3, 2017

Hey @NistorCristian!

Using {{#get "posts" filter="feature_image:-null"}} definitely works. Everything else depends on your code e.g. i can't guess if this id:-{{id}} is used in the correct context with a correct value.

P.S. In this url: https://api.ghost.org/docs/filter ... it says filter="featured:true,image:-null" and should, probably, be filter="featured:true,feature_image:-null" and images:-null shoud be feature_image:-null

Thanks will update our docs.

Closing, because this is not a bug. Please wait for help in slack, thanks!

@kirrg001 kirrg001 closed this as completed Oct 3, 2017
@NistorCristian
Copy link
Author

NistorCristian commented Oct 3, 2017

As I said {{#get "posts" filter="feature_image:-null"}} works.

But it doesn't work after I do this:
Add featured image. Save post.
Remove image. Save post.

The problem is not really with the filter tag. Is more with the fact that when I delete the featured image the value in json for feature_image becomes "" instead of null, and the post will be in the query from above, even if he doesn't have an image.

@kirrg001
Copy link
Contributor

kirrg001 commented Oct 3, 2017

Okay i see what you mean. This affects all images, because the admin client sends an empty string instead of null.

@kevinansfield Could we change this behaviour in the admin client?

@NistorCristian I don't have a workaround for you, because our parser does not allow checking for empty strings. I have added a comment here.

@kirrg001 kirrg001 reopened this Oct 3, 2017
@kirrg001 kirrg001 added the needs:info [triage] Blocked on missing information label Oct 3, 2017
@NistorCristian
Copy link
Author

@kirrg001 No problem, I'm on local. Just testing 😄

@kevinansfield
Copy link
Contributor

@kirrg001 the client behaviour can be changed but it's probably something that needs to be enforced at the server level too along with a migration to ensure consistency between old and new posts

@kirrg001 kirrg001 added server / core Issues relating to the server or core of Ghost optimisation bug [triage] something behaving unexpectedly and removed needs:info [triage] Blocked on missing information labels Oct 3, 2017
aileen added a commit to aileen/Ghost that referenced this issue Feb 27, 2018
closes TryGhost#9085

Fixes an issue, where the client sets image properties to `""` after deleting the image. This causes problems with the query filter (see TryGhost/GQL#24), as they have to be `null`.

Added a check in the model layer saving method to set value  to `null`, when the property is empty.

Affected models and properties:
- `posts`:
	- `feature_image`
	- `og_image`
	- `twitter_image`
- `users`:
	- `profile_image`
	- `cover_image`
- `tags`:
	- `feature_image`
kirrg001 pushed a commit that referenced this issue Mar 5, 2018
closes #9085

Fixes an issue, where the client sets image properties to `""` after deleting the image. This causes problems with the query filter (see TryGhost/GQL#24), as they have to be `null`.

Added a check in the model layer saving method to set value  to `null`, when the property is empty.

Affected models and properties:
- `posts`:
	- `feature_image`
	- `og_image`
	- `twitter_image`
- `users`:
	- `profile_image`
	- `cover_image`
- `tags`:
	- `feature_image`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug [triage] something behaving unexpectedly server / core Issues relating to the server or core of Ghost
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants