getlago / lago

Open Source Metering and Usage Based Billing API ⭐️ Consumption tracking, Subscription management, Pricing iterations, Payment orchestration & Revenue analytics
https://www.getlago.com
GNU Affero General Public License v3.0
7.01k stars 309 forks source link

[BUG]: Fresh Lago installation, cannot sign up ("undefined method `default_currency' for #<Organization") #314

Closed zeeshanmuhammad closed 9 months ago

zeeshanmuhammad commented 9 months ago

Describe the bug On a fresh self-hosted installation of Lago (v0.54.0-beta), it is not possible to sign up via http://localhost/sign-up , the GraphQL endpoint fails upon submitting your organization name, email address and password.

To Reproduce Steps to reproduce the behavior:

  1. Access http://localhost/sign-up
  2. Provide sample organization name, email address and password and press "Sign Up"
  3. Error pop-up occurs and docker logs shows a fatal error occured

Expected behavior On a fresh installation, with no existing database or any other cached data, a sign up should be possible so you can start administering / testing the Lago product

Support

Additional context Docker console error highlighting the failed sign up attempt:

lago-api     | I, [2024-01-19T17:10:33.138936 #16]  INFO -- : [f1f588c4-c398-4594-89d5-037572e65573] {"method":"POST","path":"/graphql","format":"*/*","controller":"GraphqlController","action":"execute","status":500,"allocations":1917,"duration":5.08,"view":0.0,"db":0.35,"ddsource":"ruby","params":{"operationName":"signup","variables":{"input":{"email":"support@example.com","password":"[FILTERED]","organizationName":"Example OrgName"}},"query":"mutation signup($input: RegisterUserInput!) {\n  registerUser(input: $input) {\n    token\n    user {\n      id\n      ...CurrentUser\n      __typename\n    }\n    __typename\n  }\n}\n\nfragment CurrentUser on User {\n  id\n  organizations {\n    id\n    name\n    timezone\n    __typename\n  }\n  __typename\n}"},"sql_queries":"'User Load (0.35) SELECT \"users\".* FROM \"users\" WHERE \"users\".\"email\" = $1 LIMIT $2'","sql_queries_count":1}
lago-api     | F, [2024-01-19T17:10:33.140240 #16] FATAL -- : [f1f588c4-c398-4594-89d5-037572e65573]   
lago-api     | [f1f588c4-c398-4594-89d5-037572e65573] NoMethodError (undefined method `default_currency' for #<Organization id: nil, name: "Example OrgName", created_at: nil, updated_at: nil, api_key: nil, webhook_url: nil, vat_rate: 0.0, country: nil, address_line1: nil, address_line2: nil, state: nil, zipcode: nil, email: nil, city: nil, logo: nil, legal_name: nil, legal_number: nil, invoice_footer: nil, document_numbering: nil>):
lago-api     | [f1f588c4-c398-4594-89d5-037572e65573]   
lago-api     | [f1f588c4-c398-4594-89d5-037572e65573] app/models/concerns/organization_timezone.rb:7:in `method_missing'
lago-api     | [f1f588c4-c398-4594-89d5-037572e65573] app/services/users_service.rb:33:in `block in register'
lago-api     | [f1f588c4-c398-4594-89d5-037572e65573] app/services/users_service.rb:32:in `register'
lago-api     | [f1f588c4-c398-4594-89d5-037572e65573] app/graphql/mutations/register_user.rb:14:in `resolve'
lago-api     | I, [2024-01-19T17:10:33.346513 #16]  INFO -- : [fecb0eb0-7f9e-4dd3-a096-c22e24177702] {"method":"POST","path":"/graphql","format":"*/*","controller":"GraphqlController","action":"execute","status":500,"allocations":1917,"duration":5.47,"view":0.0,"db":0.45,"ddsource":"ruby","params":{"operationName":"signup","variables":{"input":{"email":"support@example.com","password":"[FILTERED]","organizationName":"Example OrgName"}},"query":"mutation signup($input: RegisterUserInput!) {\n  registerUser(input: $input) {\n    token\n    user {\n      id\n      ...CurrentUser\n      __typename\n    }\n    __typename\n  }\n}\n\nfragment CurrentUser on User {\n  id\n  organizations {\n    id\n    name\n    timezone\n    __typename\n  }\n  __typename\n}"},"sql_queries":"'User Load (0.45) SELECT \"users\".* FROM \"users\" WHERE \"users\".\"email\" = $1 LIMIT $2'","sql_queries_count":1}
lago-api     | F, [2024-01-19T17:10:33.347888 #16] FATAL -- : [fecb0eb0-7f9e-4dd3-a096-c22e24177702]   
lago-api     | [fecb0eb0-7f9e-4dd3-a096-c22e24177702] NoMethodError (undefined method `default_currency' for #<Organization id: nil, name: "Example OrgName", created_at: nil, updated_at: nil, api_key: nil, webhook_url: nil, vat_rate: 0.0, country: nil, address_line1: nil, address_line2: nil, state: nil, zipcode: nil, email: nil, city: nil, logo: nil, legal_name: nil, legal_number: nil, invoice_footer: nil, document_numbering: nil>):
lago-api     | [fecb0eb0-7f9e-4dd3-a096-c22e24177702]   
lago-api     | [fecb0eb0-7f9e-4dd3-a096-c22e24177702] app/models/concerns/organization_timezone.rb:7:in `method_missing'
lago-api     | [fecb0eb0-7f9e-4dd3-a096-c22e24177702] app/services/users_service.rb:33:in `block in register'
lago-api     | [fecb0eb0-7f9e-4dd3-a096-c22e24177702] app/services/users_service.rb:32:in `register'
lago-api     | [fecb0eb0-7f9e-4dd3-a096-c22e24177702] app/graphql/mutations/register_user.rb:14:in `resolve'

Errors seems to be here:

"lago-api ... organization_timezone.rb:7:in `method_missing'"
"lago-api ... NoMethodError (undefined method `default_currency' for #<Organization id: ... "
jdenquin commented 9 months ago

Hello @zeeshanmuhammad

Can you try to update th v0.54.1-beta? It should work after!

zeeshanmuhammad commented 9 months ago

Unfortunately both v0.54.1-beta and latest main (as of 12:16pm GMT+0 23/01/2024, commit ID: 408b8594b29ee2d066db8451d1de9c82fc51ea7d) is broken. There's a lot of errors regarding these SQL columns:

organizations.credits_auto_refreshed invoices.ready_to_be_refreshed

Here's a sample of those errors:

2024-01-23 12:09:17 lago-db      | 2024-01-23 12:09:17.898 UTC [33] ERROR:  column invoices.ready_to_be_refreshed does not exist at character 43
2024-01-23 12:09:15 lago-api     | I, [2024-01-23T12:09:15.485526 #8]  INFO -- : Migrating to AddIndexToPaymentProviderCustomers (20230202110407)

2024-01-23 12:09:17 lago-db      | 2024-01-23 12:09:17.898 UTC [33] STATEMENT:  SELECT "invoices".* FROM "invoices" WHERE "invoices"."ready_to_be_refreshed" = $1 ORDER BY "invoices"."id" ASC LIMIT $2
2024-01-23 12:09:17 lago-db      | 2024-01-23 12:09:17.921 UTC [31] ERROR:  column organizations.credits_auto_refreshed does not exist at character 258

2024-01-23 12:09:17 lago-worker  | E, [2024-01-23T12:09:17.899448 #7] ERROR -- : [ActiveJob] [Clock::RefreshDraftInvoicesJob] [3c11c270-d371-4053-bbb0-f84a1659308f] Error performing Clock::RefreshDraftInvoicesJob (Job ID: 3c11c270-d371-4053-bbb0-f84a1659308f) from Sidekiq(clock) in 142.51ms: ActiveRecord::StatementInvalid (PG::UndefinedColumn: ERROR:  column invoices.ready_to_be_refreshed does not exist
2024-01-23 12:09:17 lago-worker  | LINE 1: SELECT "invoices".* FROM "invoices" WHERE "invoices"."ready_...

2024-01-23 12:09:16 lago-api     | I, [2024-01-23T12:09:16.192823 #8]  INFO -- : Migrating to AddBeforeVatToCredits (20230421094757)
2024-01-23 12:09:17 lago-worker  | /usr/local/bundle/gems/newrelic_rpm-9.5.0/lib/new_relic/agent/tracer.rb:357:in `capture_segment_error'
2024-01-23 12:09:17 lago-worker  | /usr/local/bundle/gems/newrelic_rpm-9.5.0/lib/new_relic/agent/tracer.rb:434:in `block in thread_block_with_current_transaction'
2024-01-23 12:09:17 lago-worker  | I, [2024-01-23T12:09:17.904028 #7]  INFO -- : Adding dead ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper job ba8d0313d0498ad62747f82a
2024-01-23 12:09:17 lago-worker  | I, [2024-01-23T12:09:17.908934 #7]  INFO -- : fail
2024-01-23 12:09:16 lago-api     | == 20230421094757 AddBeforeVatToCredits: migrating ============================
2024-01-23 12:09:17 lago-worker  | W, [2024-01-23T12:09:17.909681 #7]  WARN -- : {"context":"Job raised exception","job":{"retry":0,"queue":"clock","class":"ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper","wrapped":"Clock::RefreshDraftInvoicesJob","args":[{"job_class":"Clock::RefreshDraftInvoicesJob","job_id":"3c11c270-d371-4053-bbb0-f84a1659308f","provider_job_id":null,"queue_name":"clock","priority":null,"arguments":[],"executions":0,"exception_executions":{},"locale":"en","timezone":"UTC","enqueued_at":"2024-01-23T12:09:17Z","tracing_info":{"membership":null}}],"jid":"ba8d0313d0498ad62747f82a","created_at":1706011757.5482671,"trace_propagation_headers":{"sentry-trace":"184056abc0a74b3496967752d3bdd79d-9eecc06468c84b81","baggage":"sentry-trace_id=184056abc0a74b3496967752d3bdd79d,sentry-environment=production"},"enqueued_at":1706011757.5485983},"_config":{"labels":"#<Set: {}>","require":".","environment":"production","concurrency":10,"timeout":25,"poll_interval_average":null,"average_scheduled_poll_interval":5,"on_complex_arguments":"raise","error_handlers":["#<Proc:0x00007f8d50e178e8 /usr/local/bundle/gems/sidekiq-7.1.4/lib/sidekiq/config.rb:37 (lambda)>","#<Sentry::Sidekiq::ErrorHandler:0x00007f8d4f007d80>","#<Proc:0x00007f8d4e379320 /usr/local/bundle/gems/newrelic_rpm-9.5.0/lib/new_relic/agent/instrumentation/sidekiq.rb:36>"],"death_handlers":["#<Proc:0x00007f8d501823d0 /usr/local/bundle/gems/activejob-uniqueness-0.2.5/lib/active_job/uniqueness/sidekiq_patch.rb:95 (lambda)>"],"lifecycle_events":{"startup":[],"quiet":[],"shutdown":[],"heartbeat":[],"beat":["#<Proc:0x00007f8d5062b468 /usr/local/bundle/gems/sidekiq-7.1.4/lib/sidekiq/metrics/tracking.rb:133>"]},"dead_max_jobs":100000,"dead_timeout_in_seconds":15552000,"reloader":"#<Sidekiq::Rails::Reloader @app=LagoApi::Application>","backtrace_cleaner":"#<Proc:0x00007f8d4e2f4cb0 /usr/local/bundle/gems/sidekiq-7.1.4/lib/sidekiq/rails.rb:59 (lambda)>","retry":1,"queues":["default","clock","providers","billing","webhook","invoices","wallets"],"staging":{"concurrency":10},"config_file":"config/sidekiq.yml","max_retries":0,"tag":"app","identity":"de937086a131:7:803efd54e606"}}
2024-01-23 12:09:17 lago-worker  | W, [2024-01-23T12:09:17.909829 #7]  WARN -- : ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR:  column invoices.ready_to_be_refreshed does not exist
zeeshanmuhammad commented 9 months ago

Lago release v0.54.2-beta resolved issue (issues discussed via Slack channel).