Skip to content

Added getModel override param passing tests and fixes - #265

Merged
daffl merged 4 commits into
feathersjs-ecosystem:masterfrom
AndrewJDR:getmodel_param_passing_tests_and_fixes
Dec 26, 2018
Merged

daffl merged 4 commits into
feathersjs-ecosystem:masterfrom
AndrewJDR:getmodel_param_passing_tests_and_fixes

Conversation

@AndrewJDR

@AndrewJDR AndrewJDR commented Dec 22, 2018 •

Copy link
Copy Markdown
Contributor

This adds a set of service tests that ensure that all params.sequelize attributes are passed all the way down through to the getModel() of any service calls (and also to any subsequent service calls made by those service calls). This is important for reasons already outlined in #234 but I will paste the relevant section here with some slight mods:

When a service call is made by some featherjs user's code, it's important to preserve the sequelize member of the params object when making any subsequent service calls, as it's possible that the user of feathersjs intends to use these parameters as part of a getModel() override function in a custom service class (i.e. class MySpecialService extends Service with an overidden getModel() -- see PR #166) For things like multi-tenancy schemes - hosting multiple domains/sites out of a single app instance such that each site needs to hit a different database. As far as I'm aware, a getModel() override is the best way of achieving that goal, and any practice of ignoring/clobbering the params.sequelize passed in will cause problems for such a scheme.

It would be nice to have some tests in place to prevent regressions related to this functionality in the future, so that's why I've prepared these commits. Commit abcce1b adds the tests, and commit 8a95fec fixes a couple of test failures.

(Side note to @DesignByOnyx - I tried to integrate your feedback from the other PR and focused my attention on passing through only the .sequelize member of the params rather than the entire params object.)

Other note: to see the original PR that added getModel overriding with params, please see #166

This is a test to further address issue feathersjs-ecosystem#234.

While PR feathersjs-ecosystem#252 did fix some of the issues, some attributes are still
not being passed through to some of the service calls as these tests
failures will indicate. Proposed fixes for these new test failures will
be forthcoming.
This is a continuation of the work to fix issue feathersjs-ecosystem#234.
Some service calls were still failing to pass through params.sequelize,
which again could cause issues for users that are extending
the Service class with their own getModel() method that
depends upon certain parameters being passed through to it.
@AndrewJDR

AndrewJDR commented Dec 22, 2018 •

Copy link
Copy Markdown
Contributor Author

Just to respond to the comment from @DesignByOnyx over in #262:

I'm not sure this works. params is an object shared between hooks and is often a dumping ground for all sorts of data related to a service call. For example, I might have a hook at the beginning of a service call which sets some state to be used by other hooks later in the service pipeline. The params object is where this information is stored. Any information/data used in db queries should have a meaningful place - usually params.query and params.sequelize. If we need to designate other properties for holding query-specific data, we can... but using the entire params objects is not the solution IMO.

I opted to focus on passing through params.sequelize to all service calls-made-by-service-calls, e.g. in 8a95fec. But if what @DesignByOnyx is saying here is that a user shouldn't even be using params.sequelize for this "extra parameters for the overridden getModel()" purpose, we can come up with some other parameter that gets whitelisted to be passed through to all subsequent-service-calls-made-by-service-calls. I propose params.modelOptions but feel free to propose a different name.

The getModel parameter passing tests now also check that the custom
getModel method has been called by the service methods. This will
help protect against potential future regressions that somehow fail
to call getModel().
@AndrewJDR AndrewJDR changed the title Added getModel override param passing tests and fixes (still some failures, help wanted) Added getModel override param passing tests and fixes Dec 23, 2018
Comment thread test/index.test.js
return Object.assign({
sequelize: Object.assign({
expectedAttribute: EXPECTED_ATTRIBUTE_VALUE,
getModelCalls: { count: 0 }

@AndrewJDR AndrewJDR Dec 23, 2018 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, keeping count in a separate object ensures that it is maintained as a reference rather than by value across any Object.assign() calls that service calls may do. For read-only attributes this isn't important, but count is something we write to and read back from.

@daffl
daffl merged commit 33c8354 into feathersjs-ecosystem:master Dec 26, 2018
@daffl

daffl commented Dec 26, 2018

Copy link
Copy Markdown
Member

Thank you, released as v4.0.5

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