Watermelondb: Undefined error when evaluating 'this.modelClass.associations'

Created on 10 Oct 2019  Â·  5Comments  Â·  Source: Nozbe/WatermelonDB

Hi

We have an app in production which uses the watermelonDb version 0.14.0. Recently we have been getting this error in our Sentry crash reporting:

TypeError: undefined is not an object (evaluating 'this.modelClass.associations')

This generally happens when making queries to the database.

We haven't been able to replicate the issue locally but according to the crash reports it seems to be only affecting Android devices.

If anyone can offer any insight into this issue that would be great.
Thanks

Most helpful comment

Since upgrading our app to React Native version 0.60.5 and watermelon db to version 0.15.0 we have not experienced this issue.

All 5 comments

Hi

I wanted to give some more info on this issue. Below is the model class for a table in our database.

export class DroneSamples extends Model {
  static table = Tables.droneSamples;

  static associations = associations(
    [Tables.markers, {
      type: 'belongs_to',
      key: Column.markerId,
    }],
    [Tables.droneSampleImages, {
      type: 'has_many',
      foreignKey: 'drone_sample_id',
    }],
    [Tables.droneSampleLogs, {
      type: 'has_many',
      foreignKey: 'drone_sample_id',
    }],
    [Tables.droneSampleVideos, {
      type: 'has_many',
      foreignKey: 'drone_sample_id',
    }],
  );

  @field(Column.markerId) markerId: string;
  @field(Column.scoutingServiceId) scoutingServiceId: string;
  @relation(Tables.markers, Column.markerId) marker: Relation<Marker>;

  @lazy images = this.collections
    .get(Tables.images)
    .query(Q.on(Tables.droneSampleImages, 'drone_sample_id', this.id));

  @lazy logs = this.collections
    .get(Tables.logs)
    .query(Q.on(Tables.droneSampleLogs, 'drone_sample_id', this.id));

  @lazy videos = this.collections
    .get(Tables.videos)
    .query(Q.on(Tables.droneSampleVideos, 'drone_sample_id', this.id));
}

When querying the videos/images/logs for a particular droneSample, for example droneSample.videos.fetch() I will occasionally get error messages like the following in our Sentry crash logging.

Screen Shot 2019-10-28 at 10 56 08 AM

It is very difficult to replicate this as more often than not it works perfectly. I have tried to add a try/catch block around the query but the code still breaks and the error isn't caught. Hope this helps. Please let me know if there is any other info I can give to help debug this problem.

Cheers

yeah, this is really strange — we've very rarely (rarely enough that we haven't spent too much time on it) seen this issue, and haven't caught the root cause yet.

I suggest that maybe you patch your watermelondb to add a console log or something to figure out why this.modelClass is undefined -- e.g. in Query constructor

Started getting this error as well. 😓

Since upgrading our app to React Native version 0.60.5 and watermelon db to version 0.15.0 we have not experienced this issue.

Same here, stopped seeing this error after upgrading to RN v0.62.2.
But now we are seeing React Native's "Should not already be working." at almost the same frequency. So it looks like the error just mutated. Just asking here if anyone of you are also seeing it in your error logs?
https://github.com/facebook/react-native/issues/28948

Was this page helpful?
0 / 5 - 0 ratings