Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Let a broken preference schema fail loudly instead of coming back empty

Damian Legawiec92f4859ac739
diff --git a/spree/core/app/models/concerns/spree/preference_schema.rb b/spree/core/app/models/concerns/spree/preference_schema.rb
index eef11d1c4b..5e8986693e 100644
--- a/spree/core/app/models/concerns/spree/preference_schema.rb
+++ b/spree/core/app/models/concerns/spree/preference_schema.rb
@@ -80,7 +80,18 @@ module Spree
end
def compute_preference_schema
- instance = new
+ # Only instantiation is guarded. `new` touches the database to read
+ # the column list, so it fails whenever the schema is asked for before
+ # a connection exists — at boot, or in a rake task on an empty
+ # database. Describing the preferences themselves is pure Ruby, so an
+ # error there is a real bug: left inside the rescue it would return an
+ # empty schema and quietly strip every field from the admin form.
+ instance = begin
+ new
+ rescue StandardError
+ return []
+ end
+
instance.defined_preferences.filter_map do |pref|
next if instance.preference_deprecated(pref)
# Written by Spree, not supplied by the operator — a value a
@@ -96,8 +107,6 @@ module Spree
default: safe_preference_default(instance, pref)
}.freeze
end
- rescue StandardError
- []
end
# Builds a `parse_on_set:` lambda for `preference :foo_ids, :array`