Skip to content

Pass rel_opts when filtering records for record count#1234

Closed
hatch-carl wants to merge 1 commit intoJSONAPI-Resources:release-0-9from
hatch-carl:fix-record-count-when-filtering-depends-on-options
Closed

Pass rel_opts when filtering records for record count#1234
hatch-carl wants to merge 1 commit intoJSONAPI-Resources:release-0-9from
hatch-carl:fix-record-count-when-filtering-depends-on-options

Conversation

@hatch-carl
Copy link
Copy Markdown

Naturally I uncovered this because it caused a more complex bug in my app.
The problem here is that if you have a filter which depends on something
that is set in, for example, the context, you will not have that context
when the filter is re-invoked for record count, which happens when the
record count configuration is active. This only happens when fetching
related resources.

In this case I add a test where we try to fetch an author's banned books,
of which there should be only one. However, because the prior code
discards the rel_opts and instead provides an empty hash (!) the filter
does not execute because it will only operate when an admin user is in
the context. The failing test then reports the record count as 3, where it should be 1. The change to the processor class solves this issue.

Naturally I uncovered this because it caused a more complex bug in my app.
The problem here is that if you have a filter which depends on something
that is set in, for example, the context, you will not have that context
when the filter is re-invoked for record count, which happens when the
record count configuration is active. This only happens when fetching
related resources.

In this case I add a test where we try to fetch an author's banned books,
of which there should be only one. However, because the prior code
discards the rel_opts and instead provides an empty hash (!) the filter
does not execute because it will only operate when an admin user is in
the context.
lgebhardt pushed a commit that referenced this pull request Mar 22, 2019
Naturally I uncovered this because it caused a more complex bug in my app.
The problem here is that if you have a filter which depends on something
that is set in, for example, the context, you will not have that context
when the filter is re-invoked for record count, which happens when the
record count configuration is active. This only happens when fetching
related resources.

In this case I add a test where we try to fetch an author's banned books,
of which there should be only one. However, because the prior code
discards the rel_opts and instead provides an empty hash (!) the filter
does not execute because it will only operate when an admin user is in
the context.

Closes gh-1234
@lgebhardt
Copy link
Copy Markdown
Contributor

@hatch-carl Thanks!

@lgebhardt lgebhardt closed this Mar 22, 2019
st0012 pushed a commit to st0012/jsonapi-resources that referenced this pull request Aug 20, 2019
Naturally I uncovered this because it caused a more complex bug in my app.
The problem here is that if you have a filter which depends on something
that is set in, for example, the context, you will not have that context
when the filter is re-invoked for record count, which happens when the
record count configuration is active. This only happens when fetching
related resources.

In this case I add a test where we try to fetch an author's banned books,
of which there should be only one. However, because the prior code
discards the rel_opts and instead provides an empty hash (!) the filter
does not execute because it will only operate when an admin user is in
the context.

Closes JSONAPI-Resourcesgh-1234
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants