-
Notifications
You must be signed in to change notification settings - Fork 126
fix(seeds): Fix alerting seeds when no premium license is set #3860
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When no premium license is set, the `lifetime_usage_amount` alert creation failed which resulted in an error when creating the related thresholds: ``` rake aborted! ActiveRecord::RecordInvalid: Validation failed: Alert relation_must_exist (ActiveRecord::RecordInvalid) /usr/local/bundle/gems/activerecord-8.0.2/lib/active_record/validations.rb:87:in 'ActiveRecord::Validations#raise_validation_error' /usr/local/bundle/gems/activerecord-8.0.2/lib/active_record/validations.rb:54:in 'ActiveRecord::Validations#save!' /usr/local/bundle/gems/activerecord-8.0.2/lib/active_record/transactions.rb:365:in 'block in ActiveRecord::Transactions#save!' /usr/local/bundle/gems/activerecord-8.0.2/lib/active_record/transactions.rb:417:in 'block (2 levels) in ActiveRecord::Transactions#with_transaction_returning_status' /usr/local/bundle/gems/activerecord-8.0.2/lib/active_record/connection_adapters/abstract/transaction.rb:626:in 'block in ActiveRecord::ConnectionAdapters::TransactionManager#within_new_transaction' /usr/local/bundle/gems/activesupport-8.0.2/lib/active_support/concurrency/null_lock.rb:9:in 'ActiveSupport::Concurrency::NullLock#synchronize' /usr/local/bundle/gems/activerecord-8.0.2/lib/active_record/connection_adapters/abstract/transaction.rb:623:in 'ActiveRecord::ConnectionAdapters::TransactionManager#within_new_transaction' /usr/local/bundle/gems/activerecord-8.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:367:in 'ActiveRecord::ConnectionAdapters::DatabaseStatements#within_new_transaction' /usr/local/bundle/gems/activerecord-8.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:359:in 'ActiveRecord::ConnectionAdapters::DatabaseStatements#transaction' /usr/local/bundle/gems/activerecord-8.0.2/lib/active_record/transactions.rb:413:in 'block in ActiveRecord::Transactions#with_transaction_returning_status' /usr/local/bundle/gems/activerecord-8.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:412:in 'ActiveRecord::ConnectionAdapters::ConnectionPool#with_connection' /usr/local/bundle/gems/activerecord-8.0.2/lib/active_record/connection_handling.rb:310:in 'ActiveRecord::ConnectionHandling#with_connection' /usr/local/bundle/gems/activerecord-8.0.2/lib/active_record/transactions.rb:409:in 'ActiveRecord::Transactions#with_transaction_returning_status' /usr/local/bundle/gems/activerecord-8.0.2/lib/active_record/transactions.rb:365:in 'ActiveRecord::Transactions#save!' /usr/local/bundle/gems/activerecord-8.0.2/lib/active_record/suppressor.rb:56:in 'ActiveRecord::Suppressor#save!' /usr/local/bundle/gems/activerecord-8.0.2/lib/active_record/persistence.rb:55:in 'ActiveRecord::Persistence::ClassMethods#create!' /app/db/seeds/alerting.rb:69:in '<main>' /app/db/seeds.rb:4:in 'Kernel#load' /app/db/seeds.rb:4:in 'block in <main>' /app/db/seeds.rb:3:in 'Array#each' /app/db/seeds.rb:3:in '<main>' /usr/local/bundle/gems/railties-8.0.2/lib/rails/engine.rb:562:in 'Kernel#load' /usr/local/bundle/gems/railties-8.0.2/lib/rails/engine.rb:562:in 'block in Rails::Engine#load_seed' /usr/local/bundle/gems/activesupport-8.0.2/lib/active_support/callbacks.rb:120:in 'block in ActiveSupport::Callbacks#run_callbacks' /usr/local/bundle/gems/activesupport-8.0.2/lib/active_support/reloader.rb:77:in 'block in ActiveSupport::Reloader.wrap' /usr/local/bundle/gems/activesupport-8.0.2/lib/active_support/execution_wrapper.rb:91:in 'ActiveSupport::ExecutionWrapper.wrap' /usr/local/bundle/gems/activesupport-8.0.2/lib/active_support/reloader.rb:74:in 'ActiveSupport::Reloader.wrap' /usr/local/bundle/gems/railties-8.0.2/lib/rails/engine.rb:652:in 'block (2 levels) in <class:Engine>' /usr/local/bundle/gems/activesupport-8.0.2/lib/active_support/callbacks.rb:129:in 'BasicObject#instance_exec' /usr/local/bundle/gems/activesupport-8.0.2/lib/active_support/callbacks.rb:129:in 'block in ActiveSupport::Callbacks#run_callbacks' /usr/local/bundle/gems/activesupport-8.0.2/lib/active_support/callbacks.rb:140:in 'ActiveSupport::Callbacks#run_callbacks' /usr/local/bundle/gems/railties-8.0.2/lib/rails/engine.rb:562:in 'Rails::Engine#load_seed' /usr/local/bundle/gems/activerecord-8.0.2/lib/active_record/tasks/database_tasks.rb:492:in 'ActiveRecord::Tasks::DatabaseTasks#load_seed' /usr/local/bundle/gems/activerecord-8.0.2/lib/active_record/railties/databases.rake:390:in 'block (2 levels) in <main>' /usr/local/bundle/gems/bundler-2.6.8/lib/bundler/cli/exec.rb:59:in 'Kernel.load' /usr/local/bundle/gems/bundler-2.6.8/lib/bundler/cli/exec.rb:59:in 'Bundler::CLI::Exec#kernel_load' /usr/local/bundle/gems/bundler-2.6.8/lib/bundler/cli/exec.rb:23:in 'Bundler::CLI::Exec#run' /usr/local/bundle/gems/bundler-2.6.8/lib/bundler/cli.rb:452:in 'Bundler::CLI#exec' /usr/local/bundle/gems/bundler-2.6.8/lib/bundler/vendor/thor/lib/thor/command.rb:28:in 'Bundler::Thor::Command#run' /usr/local/bundle/gems/bundler-2.6.8/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in 'Bundler::Thor::Invocation#invoke_command' /usr/local/bundle/gems/bundler-2.6.8/lib/bundler/vendor/thor/lib/thor.rb:538:in 'Bundler::Thor.dispatch' /usr/local/bundle/gems/bundler-2.6.8/lib/bundler/cli.rb:35:in 'Bundler::CLI.dispatch' /usr/local/bundle/gems/bundler-2.6.8/lib/bundler/vendor/thor/lib/thor/base.rb:584:in 'Bundler::Thor::Base::ClassMethods#start' /usr/local/bundle/gems/bundler-2.6.8/lib/bundler/cli.rb:29:in 'Bundler::CLI.start' /usr/local/bundle/gems/bundler-2.6.8/exe/bundle:28:in 'block in <top (required)>' /usr/local/bundle/gems/bundler-2.6.8/lib/bundler/friendly_errors.rb:117:in 'Bundler.with_friendly_errors' /usr/local/bundle/gems/bundler-2.6.8/exe/bundle:20:in '<top (required)>' /usr/local/bundle/bin/bundle:25:in 'Kernel#load' /usr/local/bundle/bin/bundle:25:in '<main>' Tasks: TOP => db:seed (See full trace by running task with --trace) ``` Once fixed, it turned out that the `billable_metric_current_usage_amount` triggered alert creation failed as well since we did not retrieve the service result properly.
vincent-pochet
approved these changes
Jun 23, 2025
brunomiguelpinto
approved these changes
Jun 23, 2025
Thanks @vincent-pochet @brunomiguelpinto ! 🙏 |
diegocharles
pushed a commit
that referenced
this pull request
Jul 11, 2025
## Context During seeding, when no premium license is set, the `lifetime_usage_amount` alert creation fails. This results in an error when creating the related thresholds as the alert is `nil`: ```shell > lago exec -e RAILS_ENV=test api bundle exec rake db:drop db:create db:migrate db:seed Dropped database 'lago_test' Dropped database 'lago_test' Dropped database 'default_test' Created database 'lago_test' ... rake aborted! ActiveRecord::RecordInvalid: Validation failed: Alert relation_must_exist (ActiveRecord::RecordInvalid) /usr/local/bundle/gems/activerecord-8.0.2/lib/active_record/validations.rb:87:in 'ActiveRecord::Validations#raise_validation_error' ... /app/db/seeds/alerting.rb:69:in '<main>' /app/db/seeds.rb:4:in 'Kernel#load' /app/db/seeds.rb:4:in 'block in <main>' /app/db/seeds.rb:3:in 'Array#each' /app/db/seeds.rb:3:in '<main>' /usr/local/bundle/gems/railties-8.0.2/lib/rails/engine.rb:562:in 'Kernel#load' ... /usr/local/bundle/bin/bundle:25:in '<main>' Tasks: TOP => db:seed (See full trace by running task with --trace) ``` ## Description This commit fixes it by checking whether `License.premium?` is `true`. Once fixed, it turned out that the `billable_metric_current_usage_amount` triggered alert creation failed as well since we did not retrieve the service result properly.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
During seeding, when no premium license is set, the
lifetime_usage_amount
alert creation fails. This results in an error when creating the related thresholds as the alert isnil
:Description
This PR fixes it by checking whether
License.premium?
istrue
.Once fixed, it turned out that the
billable_metric_current_usage_amount
triggered alert creation failed as well since we did not retrieve the service result properly.