basecamp / audits1984

Auditing tool for Rails console sessions
MIT License
358 stars 26 forks source link

Postgres compatibility #5

Closed excid3 closed 3 years ago

excid3 commented 3 years ago

Ran into this running on a Postgres app, but wasn't able to pinpoint what needed to change.

ActionView::Template::Error (PG::InvalidColumnReference: ERROR:  for SELECT DISTINCT, ORDER BY expressions must appear in select list
LINE 1: ...ated_at <= '2021-08-30 23:59:59.999999') ORDER BY "console19...
                                                             ^
):
    1: <article class="message is-info">
    2:   <div class="message-body">
    3:     <%= sessions.count %> sessions (<%= sessions.pending.count %> pending, <%= sessions.approved.count %> approved, <%= sessions.flagged.count %> flagged)
    4:   </div>
    5: </article>

rails (0a4410dace9a) activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:726:in `exec_params'
rails (0a4410dace9a) activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:726:in `block (2 levels) in exec_no_cache'
rails (0a4410dace9a) activesupport/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads'
rails (0a4410dace9a) activesupport/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares'
rails (0a4410dace9a) activesupport/lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads'
rails (0a4410dace9a) activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:725:in `block in exec_no_cache'
rails (0a4410dace9a) activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:737:in `block (2 levels) in log'
rails (0a4410dace9a) activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
rails (0a4410dace9a) activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
rails (0a4410dace9a) activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
rails (0a4410dace9a) activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
rails (0a4410dace9a) activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
rails (0a4410dace9a) activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:736:in `block in log'
rails (0a4410dace9a) activesupport/lib/active_support/notifications/instrumenter.rb:24:in `instrument'
rails (0a4410dace9a) activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:727:in `log'
rails (0a4410dace9a) activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:724:in `exec_no_cache'
rails (0a4410dace9a) activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:703:in `execute_and_clear'
rails (0a4410dace9a) activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb:52:in `exec_quer

I think the Auditable distinct calls need to use a group_by instead?

scope :sensitive, -> { joins(:sensitive_accesses).distinct }
jorgemanrubia commented 3 years ago

Hey @excid3 I'll look into it this week. Thanks for these reports, this certainly should be compatible with postgres!

jorgemanrubia commented 3 years ago

Released v0.1.1 with a fix for this.