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

Exception in changedobserveChanges callback: Error: Cannot read property 'documents' of undefined #73

Closed
lc3t35 opened this issue Oct 30, 2022 · 9 comments · Fixed by #75

Comments

@lc3t35
Copy link

lc3t35 commented Oct 30, 2022

Hi, I have this strange error (meteor 1.8, tunguska-reactive-aggregate 1.3.10)

2022-10-30 18:29:33+01:00 Exception in changedobserveChanges callback: Error: Cannot read property 'documents' of undefined
cr7ta
2022-10-30 18:29:33+01:00 at update (packages/tunguska:reactive-aggregate/aggregate.js:282:13)
cr7ta
2022-10-30 18:29:33+01:00 at debounce (packages/tunguska:reactive-aggregate/aggregate.js:301:7)
cr7ta
2022-10-30 18:29:33+01:00 at changed (packages/tunguska:reactive-aggregate/aggregate.js:323:9)
cr7ta
2022-10-30 18:29:33+01:00 at runWithEnvironment (packages/meteor.js:1347:24)
cr7ta
2022-10-30 18:29:33+01:00 at packages/meteor.js:1360:14
cr7ta
2022-10-30 18:29:33+01:00 at packages/mongo/observe_multiplex.js:178:30
cr7ta
2022-10-30 18:29:33+01:00 at Array.forEach (<anonymous>)
cr7ta
2022-10-30 18:29:33+01:00 at Function._.each._.forEach (packages/underscore.js:139:11)
cr7ta
2022-10-30 18:29:33+01:00 at Object.task (packages/mongo/observe_multiplex.js:172:9)
cr7ta
2022-10-30 18:29:33+01:00 at Meteor._SynchronousQueue.SQp._run (packages/meteor.js:924:16)
cr7ta
2022-10-30 18:29:33+01:00 at packages/meteor.js:901:12
cr7ta
2022-10-30 18:29:34+01:00Exception in setTimeout callback: Error: Cannot read property 'documents' of undefined
cr7ta
2022-10-30 18:29:34+01:00 at update (packages/tunguska:reactive-aggregate/aggregate.js:282:13)
cr7ta
2022-10-30 18:29:34+01:00 at packages/tunguska:reactive-aggregate/aggregate.js:294:7
cr7ta
2022-10-30 18:29:34+01:00 at Meteor.EnvironmentVariable.EVp.withValue (packages/meteor.js:1259:12)
cr7ta
2022-10-30 18:29:34+01:00 at packages/meteor.js:557:25
cr7ta
2022-10-30 18:29:34+01:00 at runWithEnvironment (packages/meteor.js:1347:24)
@robfallows
Copy link
Owner

There's only one place in the code where that can appear:

const previousFields = [...sub._session.collectionViews.get(localOptions.clientCollection).documents.get(doc_id).dataByKey.keys()];

Is it possible there's no client collection defined?

@lc3t35
Copy link
Author

lc3t35 commented Nov 1, 2022

FYI, I've updated existing meteor 2.2 to 2.8 and latest tunguska-reactive-aggregate 1.3.10 - you can edit the title of Readme still at 1.3.9)
clientCollection is optional ("defaults to the same name as the original collection"), so it is not defined in every aggregates in my code.
It should be by default :

clientCollection: collection._name,

let's check if sub._session.collectionViews.get(localOptions.clientCollection) exist before getting .documents of it ? if not log : localOptions.clientCollection and keys of sub._session.collectionViews :

if ( sub._session.collectionViews.get(localOptions.clientCollection) === undefined) {
   function logMapKeys(value, key) { console.log(`${key}`);}
   console.log(
      '#73 localOptions.clientCollection : ', localOptions.clientCollection, sub._session.collectionViews.forEach(logMapKeys)
   );
} else {
...
}

Deployed to get more information ...

@lc3t35
Copy link
Author

lc3t35 commented Nov 4, 2022

here is the log :

2022-11-02 10:17:18+01:00Settings updated for user : v...L
2022-11-02 14:55:35+01:00Settings updated for user : v...L
2022-11-02 16:10:57+01:00#73 localOptions.clientCollection : moments undefined
2022-11-02 16:10:57+01:00#73 localOptions.clientCollection : moments undefined
2022-11-02 16:10:57+01:00#73 localOptions.clientCollection : moments undefined
2022-11-02 16:10:57+01:00#73 localOptions.clientCollection : moments undefined
2022-11-02 16:10:57+01:00#73 localOptions.clientCollection : moments undefined
2022-11-02 16:10:57+01:00#73 localOptions.clientCollection : moments undefined
2022-11-02 16:10:57+01:00#73 localOptions.clientCollection : moments undefined
2022-11-02 16:10:57+01:00#73 localOptions.clientCollection : moments undefined
2022-11-02 16:10:57+01:00#73 localOptions.clientCollection : moments undefined
2022-11-02 16:10:57+01:00#73 localOptions.clientCollection : moments undefined
2022-11-02 16:10:57+01:00#73 localOptions.clientCollection : pensees undefined
2022-11-02 16:10:57+01:00#73 localOptions.clientCollection : pensees undefined
2022-11-02 16:10:57+01:00#73 localOptions.clientCollection : pensees undefined
2022-11-02 16:10:57+01:00#73 localOptions.clientCollection : pensees undefined
2022-11-02 16:10:57+01:00#73 localOptions.clientCollection : pensees undefined
2022-11-02 16:10:57+01:00#73 localOptions.clientCollection : pensees undefined
2022-11-02 16:10:57+01:00#73 localOptions.clientCollection : pensees undefined
2022-11-02 16:10:57+01:00#73 localOptions.clientCollection : pensees undefined
2022-11-02 16:10:57+01:00#73 localOptions.clientCollection : pensees undefined
2022-11-02 16:10:57+01:00#73 localOptions.clientCollection : pensees undefined
2022-11-02 16:10:58+01:00#73 localOptions.clientCollection : moments undefined
2022-11-02 16:10:58+01:00#73 localOptions.clientCollection : moments undefined
2022-11-02 16:10:58+01:00#73 localOptions.clientCollection : moments undefined
2022-11-02 16:10:58+01:00#73 localOptions.clientCollection : moments undefined
2022-11-02 16:10:58+01:00#73 localOptions.clientCollection : moments undefined
2022-11-02 16:10:58+01:00#73 localOptions.clientCollection : moments undefined
2022-11-02 16:10:58+01:00#73 localOptions.clientCollection : moments undefined
2022-11-02 16:10:58+01:00#73 localOptions.clientCollection : moments undefined
2022-11-02 16:10:58+01:00#73 localOptions.clientCollection : moments undefined
2022-11-02 16:10:58+01:00#73 localOptions.clientCollection : moments undefined
2022-11-02 16:12:21+01:00Settings updated for user : J...h
2022-11-02 16:17:49+01:00Settings updated for user : v...L

so we are losing sub._session.collectionViews ....

@robfallows
Copy link
Owner

Hmm. I've just checked the Meteor code - the use of _ names on properties is always risky. However, it's still present.

What's your code for defining the publication?

@lc3t35
Copy link
Author

lc3t35 commented Nov 4, 2022

the problem is not at collection._name (displayed in log as "moments", "pensees") but that sub._session.collectionViews is undefined

code :

Meteor.publish(
  'moments.followedById',
  function (userId, limit = 5) {
    ....
    ReactiveAggregate(
      this,
      Moments,
      [ .... ],
      {
        noAutomaticObserver: true,
        debounceDelay: 100,
        observers: [
          Moments.find({}),
          Contacts.find({}),
          Contacts.find({
            $or: [
              { $where: 'this.followedBy.length >= 0' },
              { $where: 'this.following.length >= 0' },
              { $where: 'this.blocked.length >= 0' },
            ],
          }),
          Meteor.users.find({}),
        ],
      }

@robfallows
Copy link
Owner

Agreed, but there was a possibility that this was not valid (if you'd used => instead of function()).

@lc3t35
Copy link
Author

lc3t35 commented Nov 4, 2022

Thank you Rob for your time, if the user is disconnected for a few seconds, would this be the cause of the issue ?

@robfallows
Copy link
Owner

If you enable the debug option, do you get a notification about the observers being stopped?

sub.onStop(() => {
if (options.debug) console.log(`Reactive-Aggregate: stopping observers`)

@georgekovach
Copy link
Contributor

Hello guys,

I've created a single-line PR which fixed this issue for me.

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 a pull request may close this issue.

3 participants