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

Using Collection Hook's direct version breaks defaultValue and autoValue on an insert #452

Open
evolross opened this issue Jul 9, 2024 · 5 comments

Comments

@evolross
Copy link

evolross commented Jul 9, 2024

Describe the bug

Ran into an issue upgrading my project to Meteor 2.16 from 2.7.2 (on my way up to 3.0).

When using aldeed:collection2@4.0.2 with the included aldeed:simple-schema@1.13.1 on a Meteor 2.16 project along with matb33:collection-hooks@1.3.1 (latest version), using the collection hook's direct versions that bypass a collection's hook will cause the defaultValue and autoValue set in the schema to also not run. The added logic in the defined simple schema gets bypassed and the document gets inserted/updated as if simple schema doesn't exist. I have tested matb33:collection-hooks and it seems the problem is rooted in aldeed:collection2 or aldeed:simple-schema. If you drop back down to aldeed:collection2@3.5.0 and use meteor npm install simpl-schema@1.12.3 with any version of matb33:collection-hooks all works as expected.

To Reproduce

I've hotrodded the React Simple Todos demo to display the error in a repo here.

The repo has the following currently added:

aldeed:collection2@4.0.2
aldeed:simple-schema@1.13.1
matb33:collection-hooks@1.3.1

Start the repo with the meteor command.

  1. Click on the Add New Link button.

A link will be inserted in the list without using the direct version in the insert. The insert is performed and the link's description and createdAt are all successfully set using either Simple Schema's defaultValue or autoValue. You'll also notice the link's linkType is updated to "video" by the defined and working LinksCollection.before.insert hook.

  1. Click on the Add New Link (Direct) button.

A link will be inserted in the list using the direct version in the insert. The insert is performed but the link will not get any of the Simple Schema logic (e.g. defaultValue or autoValue) however it does get inserted. And the hook is not performed so its linkType is still "website".

Expected behavior

Making use of a matb33:collection-hook direct call should still run the Simple Schema logic (e.g. defaultValue or autoValue) and validation. Using aldeed:collection2@3.5.0 and meteor npm install simpl-schema@1.12.3 all works as expected. Feel free to comment out aldeed:collection2 and uncomment aldeed:collection2@3.5.0 in the packages.js file and then do a meteor npm install simpl-schema@1.12.3 and then update the import in links.js to see it working correctly on the prior versions.

Copy link

github-actions bot commented Jul 9, 2024

Thank you for submitting this issue!

We, the Members of Meteor Community Packages take every issue seriously.
Our goal is to provide long-term lifecycles for packages and keep up
with the newest changes in Meteor and the overall NodeJs/JavaScript ecosystem.

However, we contribute to these packages mostly in our free time.
Therefore, we can't guarantee you issues to be solved within certain time.

If you think this issue is trivial to solve, don't hesitate to submit
a pull request, too! We will accompany you in the process with reviews and hints
on how to get development set up.

Please also consider sponsoring the maintainers of the package.
If you don't know who is currently maintaining this package, just leave a comment
and we'll let you know

@jankapunkt
Copy link
Member

Hi @evolross thanks for the reporting. If on Collection2@3.5.0 plus NPM simple schema, can you please use npm install simpl-schema@1.13.1, which was the latest simple schema release compatible with Meteor.

Just to see if the issue is really related to simple schema or collection 2. This is because aldeed:simple-schema@1.13.1 is a 1:1 release of this NPM version in order to provide a basis for a hard-fork with continued Meteor support.

@evolross
Copy link
Author

So yes, using aldeed:collection2@3.5.0 and npm simpl-schema@1.13.1 works as expected. This is essentially the same as my Meteor 2.7.2 configuration except the slightly newer npm simpl-schema.

I'm thinking it has something to do with load ordering of aldeed:collection2, the meteor aldeed:simple-schema, and matb33:collection-hooks. It seems the direct version in the collection hook is calling a version of insert that does not have all the simple-schema logic on it. I did previously try experimenting with load ordering of the packages and that didn't seem to help.

@evolross
Copy link
Author

Upon some thought, I thought for sure this was a load order issue with collection-hooks.

I moved aldeed:collection2@4.0.2, aldeed:simple-schema@1.13.1, matb33:collection-hooks@1.3.1 to the packages folder and added logs to see which was loading first.

For matb33:collection-hooks I logged when the direct versions get set up and for aldeed:simple-schema I logged when the defaultValue calls are set up.

As I thought, the collection hook direct calls get called first. Which seems problematic as it would seem the direct calls need to have the simple schema logic added first or else they'll be missing it and thus cause the bug here.

As a sanity check, I changed the repo back to aldeed:collection2@3.5.0 and npm simpl-schema@1.13.1, added the logs into node_modules for simpl-schema and oddly, the load ordering is the same and it works as expected.

@evolross
Copy link
Author

So my original configuration has the same load order as the new configuration, but the original configuration works.

I am noticing that in the new configuration simple-schema's validate is not being called which is the problem. I just don't know why it's not being called.

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

No branches or pull requests

2 participants