iknow_view_models 3.14.4 → 3.14.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d2167f858fe318caa9d87ee64a0d3a3898226f5705c596549094894be334a62f
4
- data.tar.gz: d45adf1829482a676d47a820be735d3ae7385b27ad6cb7406e0d6a62b77cf7fa
3
+ metadata.gz: b22d72f47ed8a1192f131bd4acce1a62ded93bac8dac0d17044d44cbb0b5e445
4
+ data.tar.gz: 4fb0a382d2cb24a99a2df2ef6aacd492743fd4ff6a496cfde48b77e291afa178
5
5
  SHA512:
6
- metadata.gz: 897fb03fe571579b5b8d2d259ac2705ac176ae779deda665b662ef90421ae09aeec829468f863f3c63e6bc1946480ffd971687a57c920477bfb65a66025d7dae
7
- data.tar.gz: d931e8d90d6cf5f4440053df982d507f090a75ee6fe96cd8a511952d7b0e04a86a51624afcc209c98f75b05a852c35192ce36cd095d9ea3de38bfe1cf6f18f30
6
+ metadata.gz: da7f91b5d04c4042cf0b959f65610da12bb0eaf54ffef78e8469c0637b0e9274813b8e04f2bb0c4b1e8cb47bccc3a3d0a7febf9e2a34b3405220d8ba8f3bbe66
7
+ data.tar.gz: ad2db4486ea34a6a0b4790d1d620784fccf3887a46bee02d6f25f80983adf81cc4229ef5cf2f10d79a7d0d05f15a7ee16ad1a46d52097073b049497046801149
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IknowViewModels
4
- VERSION = '3.14.4'
4
+ VERSION = '3.14.5'
5
5
  end
@@ -377,7 +377,36 @@ class ViewModel
377
377
  when PG::UniqueViolation, PG::ExclusionViolation
378
378
  UniqueViolation.from_postgres_error(exception.cause, nodes)
379
379
  else
380
- self.new(exception.message, nodes)
380
+ self.new(redact_failing_row(exception), nodes)
381
+ end
382
+ end
383
+
384
+ class << self
385
+ FAILING_ROW_PREFIX = 'Failing row contains '
386
+ REDACTED_FAILING_ROW = 'Failing row contains (redacted).'
387
+
388
+ private
389
+
390
+ # Postgres reports CHECK and NOT NULL violations with "Failing row
391
+ # contains (...)" including every column of the row being written.
392
+ # Redact them.
393
+ def redact_failing_row(exception)
394
+ message = exception.message
395
+
396
+ pg_error = exception.cause
397
+ row_detail = pg_error.result&.error_field(PG::PG_DIAG_MESSAGE_DETAIL) if pg_error.is_a?(PG::Error)
398
+
399
+ if row_detail&.start_with?(FAILING_ROW_PREFIX) && message.include?(row_detail)
400
+ # With a structured error, replace the exact detail reported by
401
+ # Postgres rather than parsing the message.
402
+ message.sub(row_detail) { REDACTED_FAILING_ROW }
403
+ elsif (index = message.index(FAILING_ROW_PREFIX))
404
+ # Without a structured error we can't find the end of the message,
405
+ # so drop everything after it.
406
+ message[0, index] + REDACTED_FAILING_ROW
407
+ else
408
+ message
409
+ end
381
410
  end
382
411
  end
383
412
  end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../test_helper'
4
+
5
+ require 'pg'
6
+ require 'view_model'
7
+ require 'view_model/deserialization_error'
8
+
9
+ class ViewModel::DeserializationError::DatabaseConstraintTest < ActiveSupport::TestCase
10
+ extend Minitest::Spec::DSL
11
+
12
+ describe 'from_exception' do
13
+ let(:error) { ViewModel::DeserializationError::DatabaseConstraint.from_exception(exception) }
14
+
15
+ describe 'without a Postgres error' do
16
+ let(:exception) do
17
+ ActiveRecord::StatementInvalid.new(
18
+ %(PG::CheckViolation: ERROR: new row for relation "t" violates check constraint "c"\nDETAIL: Failing row contains (1, SECRET).\n))
19
+ end
20
+
21
+ it 'redacts everything from the failing row' do
22
+ expect(error.detail).to eq(
23
+ %(PG::CheckViolation: ERROR: new row for relation "t" violates check constraint "c"\nDETAIL: Failing row contains (redacted).))
24
+ end
25
+ end
26
+
27
+ describe 'without a failing row' do
28
+ let(:exception) do
29
+ ActiveRecord::StatementInvalid.new(%(PG::ForeignKeyViolation: ERROR: insert or update on table "t" violates foreign key constraint "fk"))
30
+ end
31
+
32
+ it 'retains the message' do
33
+ expect(error.detail).to eq(exception.message)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -101,6 +101,40 @@ class ViewModel::ErrorWrappingTest < ActiveSupport::TestCase
101
101
 
102
102
  expect(ex.message).to match(/violates check constraint/)
103
103
  end
104
+
105
+ it 'redacts the failing row' do
106
+ ex = assert_raises(ViewModel::DeserializationError::DatabaseConstraint) do
107
+ subject.wrap_active_record_errors(blame) do
108
+ model_class.create!(name: "SECRET).\nVALUE")
109
+ end
110
+ end
111
+
112
+ expect(ex.detail).to match(/violates check constraint/)
113
+ expect(ex.detail).to include('Failing row contains (redacted).')
114
+ expect(ex.detail).not_to include('SECRET')
115
+ expect(ex.detail).not_to include('VALUE')
116
+ expect(ex.nodes).to eq([blame])
117
+ end
118
+ end
119
+
120
+ describe 'not-null constraint' do
121
+ def model_attributes
122
+ super.merge(
123
+ schema: ->(t) { t.string :required, null: false },
124
+ )
125
+ end
126
+
127
+ it 'redacts the failing row' do
128
+ ex = assert_raises(ViewModel::DeserializationError::DatabaseConstraint) do
129
+ subject.wrap_active_record_errors(blame) do
130
+ model_class.create!(name: 'SECRET')
131
+ end
132
+ end
133
+
134
+ expect(ex.detail).to match(/null value in column "required" .* violates not-null constraint/)
135
+ expect(ex.detail).to include('Failing row contains (redacted).')
136
+ expect(ex.detail).not_to include('SECRET')
137
+ end
104
138
  end
105
139
 
106
140
  describe 'unique constraint' do
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iknow_view_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.14.4
4
+ version: 3.14.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - iKnow Team
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2026-02-10 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: actionpack
@@ -529,6 +528,7 @@ files:
529
528
  - test/unit/view_model/active_record_test.rb
530
529
  - test/unit/view_model/callbacks_test.rb
531
530
  - test/unit/view_model/controller_test.rb
531
+ - test/unit/view_model/deserialization_error/database_constraint_test.rb
532
532
  - test/unit/view_model/deserialization_error/unique_violation_test.rb
533
533
  - test/unit/view_model/error_wrapping_test.rb
534
534
  - test/unit/view_model/garbage_collection_test.rb
@@ -540,7 +540,6 @@ homepage: https://github.com/iknow/cerego_view_models
540
540
  licenses:
541
541
  - MIT
542
542
  metadata: {}
543
- post_install_message:
544
543
  rdoc_options: []
545
544
  require_paths:
546
545
  - lib
@@ -555,8 +554,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
555
554
  - !ruby/object:Gem::Version
556
555
  version: '0'
557
556
  requirements: []
558
- rubygems_version: 3.1.6
559
- signing_key:
557
+ rubygems_version: 3.6.9
560
558
  specification_version: 4
561
559
  summary: ViewModels provide a means of encapsulating a collection of related data
562
560
  and specifying its JSON serialization.
@@ -593,6 +591,7 @@ test_files:
593
591
  - test/unit/view_model/active_record_test.rb
594
592
  - test/unit/view_model/callbacks_test.rb
595
593
  - test/unit/view_model/controller_test.rb
594
+ - test/unit/view_model/deserialization_error/database_constraint_test.rb
596
595
  - test/unit/view_model/deserialization_error/unique_violation_test.rb
597
596
  - test/unit/view_model/error_wrapping_test.rb
598
597
  - test/unit/view_model/garbage_collection_test.rb