Skip to content

Create a new SJ API without the field display_collection in the schema breaks all API endpoints. #199

@motizuki

Description

@motizuki

Describe the bug
I believe the metrics use the display_collection to calculate metrics based on collections which make this field required for the API to function, this is required even with the config log_metrics = false

Was this intentional? If so we need to add some docs to and instruct users to create a display_collection field on their schema, and also explain what this field is for.

To Reproduce
Steps to reproduce the behavior:

  1. Setup a new API using the version v3.6.3 of the SJ engine.
  2. Make sure the Record schema doesn't have a Display Collection field
  3. Harvest some records
  4. Perform a search
  5. You should see a 500 error saying that the method display_collection doesn't exist.

Expected behavior
Maybe this method should also check for the config log_metrics value?
https://github.com/DigitalNZ/supplejack_api/blob/0b904b55f46d091fb9c5947ea90e362f33a448d5/app/controllers/supplejack_api/concerns/ignore_metrics.rb

Screenshots
n/a

Logs

NoMethodError (undefined method `display_collection' for #<SupplejackApi::ApiRecord::RecordFragment:0x00007f9daf6adb88>
Did you mean?  display_date):

mongoid (7.0.6) lib/mongoid/attributes/dynamic.rb:138:in `method_missing'
/Users/gus/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/bundler/gems/supplejack_api-fc4bdfffce1a/app/models/supplejack_api/support/fragment_helpers.rb:81:in `public_send'
/Users/gus/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/bundler/gems/supplejack_api-fc4bdfffce1a/app/models/supplejack_api/support/fragment_helpers.rb:81:in `method_missing'
/Users/gus/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/bundler/gems/supplejack_api-fc4bdfffce1a/app/controllers/supplejack_api/concerns/records_controller_metrics.rb:19:in `block in log_search
'
/Users/gus/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/bundler/gems/supplejack_api-fc4bdfffce1a/app/controllers/supplejack_api/concerns/records_controller_metrics.rb:18:in `map'
/Users/gus/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/bundler/gems/supplejack_api-fc4bdfffce1a/app/controllers/supplejack_api/concerns/records_controller_metrics.rb:18:in `log_search'
activesupport (5.1.7) lib/active_support/callbacks.rb:413:in `block in make_lambda'
activesupport (5.1.7) lib/active_support/callbacks.rb:235:in `block in halting_and_conditional'
activesupport (5.1.7) lib/active_support/callbacks.rb:511:in `block in invoke_after'
activesupport (5.1.7) lib/active_support/callbacks.rb:511:in `each'
...

Configuration files

SupplejackApi.setup do |config|
  config.record_class = SupplejackApi::Record
  config.preview_record_class = SupplejackApi::PreviewRecord
  config.log_metrics = false
  config.record_batch_size_for_mongo_queries_and_solr_indexing = 500
end

Environment:
docker

Additional context
n/a

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions