Skip to content

Some attributes mistakenly treated as unknown when working with lockbox and one_of #234

Description

@dweinand

Here's roughly the code I have:

class PlatformConfiguration < ActiveRecord::Base
  has_encrypted :properties, type: Properties.to_type
end

class PlatformConfiguration
  PROPERTIES_MODELS = {
    'platform' => 'PlatformProperties'
  }

  Properties = StoreModel.one_of do |json|
    const_get(PROPERTIES_MODELS.fetch(json[:platform_service], 'EmptyProperties'))
  end
end

class PlatformConfiguration
  class EmptyProperties
    include StoreModel::Model

    attribute :platform_service, :string
  end
end

class PlatformConfiguration
  class PlatformProperties
    include StoreModel::Model

    attribute :platform_service, :string
    attribute :api_key, :string
  end
end

I've verified that the types work correctly when manually casting values, however when I set values like platform_configuration.properties = {platform_service: 'platform', api_key: '12345'} && platform_configuration.save, properties.platform_service shows up correctly, but properties.api_key ends up showing up as an unknown attribute even though it's reporting the correct PlatformProperties type.

We're on:

  • rails 8.1
  • ruby 3.3.10
  • store_model 4.3.0
  • lockbox 1.4.1

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions