Skip to content

change from present? (Rails) to native Ruby check #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ Any schema can be multi-tenant
```ruby
client.schema.create(
# Other keys...
mutli_tenant: true, # passes { enabled: true } to weaviate
multi_tenant: true, # passes { enabled: true } to weaviate
)
```

Expand All @@ -368,7 +368,18 @@ You can also manually specify your multi tenancy configuration with a hash
```ruby
client.schema.create(
# Other keys...
mutli_tenant: { enabled: true, autoTenantCreation: true, autoTenantActivation: true },
multi_tenant: { enabled: true, autoTenantCreation: true, autoTenantActivation: true },
)
```

Added shortcuts for `multiTenancyConfig`:

```ruby
client.schema.create(
# Other keys...
multi_tenant: true,
auto_tenant_creation: true,
auto_tenant_activation: true
)
```

Expand Down
2 changes: 1 addition & 1 deletion lib/weaviate/objects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def create(
req.body = {}
req.body["class"] = class_name
req.body["properties"] = properties
req.body["tenant"] = tenant unless tenant.blank?
req.body["tenant"] = tenant unless tenant.nil?
req.body["id"] = id unless id.nil?
req.body["vector"] = vector unless vector.nil?
end
Expand Down
8 changes: 6 additions & 2 deletions lib/weaviate/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
description: nil,
properties: nil,
multi_tenant: nil,
auto_tenant_creation: nil,
auto_tenant_activation: nil,
Copy link
Collaborator

@andreibondarev andreibondarev Sep 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like it would be simpler to just default to false as that's what Weaviate itself does:

def create(
    ...
    multi_tenant: false,
    auto_tenant_creation: false,
    auto_tenant_activation: false

And we'd just always set those values:

req.body["multiTenancyConfig"] = {enabled: multi_tenant, autoTenantCreation: auto_tenant_creation, autoTenantActivation: auto_tenant_activation}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that it was strange that multi_tenant was the only arg that didn't match the weaviate arg, but didn't want to make a whole lot of changes in this PR.

MultiTenancyConfig = Struct.new(:enabled, :autoTenantCreation, :autoTenantActivation) do
  def initialize(enabled: false, autoTenantCreation: false, autoTenantActivation: false)
    super
  end
end
create(
  ... 
  multi_tenancy_config: MultiTenancyConfig.new
)

Since this can be used in update as well, I think it'd make sense to have a small Struct that defines the options.

For now, I'll go with your suggestion, because we are way off track of fixing the present? / blank? issue

Copy link
Contributor Author

@mculp mculp Sep 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, just to be sure, you want me to blow away the existing code for this? I was trying to keep it backwards compatible.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please!

I think it's okay, I'll release a 0.10 to signify the breaking change here.

vector_index_type: nil,
vector_index_config: nil,
vectorizer: nil,
Expand All @@ -45,8 +47,10 @@
req.body["properties"] = properties unless properties.nil?
if multi_tenant.is_a?(Hash)
req.body["multiTenancyConfig"] = multi_tenant
elsif multi_tenant.present?
req.body["multiTenancyConfig"] = {enabled: true}
elsif !multi_tenant.nil?
req.body["multiTenancyConfig"] = { enabled: true }

Check failure on line 51 in lib/weaviate/schema.rb

View workflow job for this annotation

GitHub Actions / tests (3.0)

Layout/SpaceInsideHashLiteralBraces: Space inside { detected.

Check failure on line 51 in lib/weaviate/schema.rb

View workflow job for this annotation

GitHub Actions / tests (3.0)

Layout/SpaceInsideHashLiteralBraces: Space inside } detected.

Check failure on line 51 in lib/weaviate/schema.rb

View workflow job for this annotation

GitHub Actions / tests (3.1)

Layout/SpaceInsideHashLiteralBraces: Space inside { detected.

Check failure on line 51 in lib/weaviate/schema.rb

View workflow job for this annotation

GitHub Actions / tests (3.1)

Layout/SpaceInsideHashLiteralBraces: Space inside } detected.

Check failure on line 51 in lib/weaviate/schema.rb

View workflow job for this annotation

GitHub Actions / tests (3.3)

Layout/SpaceInsideHashLiteralBraces: Space inside { detected.

Check failure on line 51 in lib/weaviate/schema.rb

View workflow job for this annotation

GitHub Actions / tests (3.3)

Layout/SpaceInsideHashLiteralBraces: Space inside } detected.
req.body["multiTenancyConfig"].merge!(autoTenantCreation: true) unless auto_tenant_creation.nil?

Check failure on line 52 in lib/weaviate/schema.rb

View workflow job for this annotation

GitHub Actions / tests (3.0)

Performance/RedundantMerge: Use `req.body["multiTenancyConfig"][:autoTenantCreation] = true` instead of `req.body["multiTenancyConfig"].merge!(autoTenantCreation: true)`.

Check failure on line 52 in lib/weaviate/schema.rb

View workflow job for this annotation

GitHub Actions / tests (3.1)

Performance/RedundantMerge: Use `req.body["multiTenancyConfig"][:autoTenantCreation] = true` instead of `req.body["multiTenancyConfig"].merge!(autoTenantCreation: true)`.

Check failure on line 52 in lib/weaviate/schema.rb

View workflow job for this annotation

GitHub Actions / tests (3.3)

Performance/RedundantMerge: Use `req.body["multiTenancyConfig"][:autoTenantCreation] = true` instead of `req.body["multiTenancyConfig"].merge!(autoTenantCreation: true)`.
req.body["multiTenancyConfig"].merge!(autoTenantActivation: true) unless auto_tenant_activation.nil?

Check failure on line 53 in lib/weaviate/schema.rb

View workflow job for this annotation

GitHub Actions / tests (3.0)

Performance/RedundantMerge: Use `req.body["multiTenancyConfig"][:autoTenantActivation] = true` instead of `req.body["multiTenancyConfig"].merge!(autoTenantActivation: true)`.

Check failure on line 53 in lib/weaviate/schema.rb

View workflow job for this annotation

GitHub Actions / tests (3.1)

Performance/RedundantMerge: Use `req.body["multiTenancyConfig"][:autoTenantActivation] = true` instead of `req.body["multiTenancyConfig"].merge!(autoTenantActivation: true)`.

Check failure on line 53 in lib/weaviate/schema.rb

View workflow job for this annotation

GitHub Actions / tests (3.3)

Performance/RedundantMerge: Use `req.body["multiTenancyConfig"][:autoTenantActivation] = true` instead of `req.body["multiTenancyConfig"].merge!(autoTenantActivation: true)`.
end
req.body["invertedIndexConfig"] = inverted_index_config unless inverted_index_config.nil?
req.body["replicationConfig"] = replication_config unless replication_config.nil?
Expand Down
25 changes: 25 additions & 0 deletions spec/weaviate/schema_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,31 @@
)
expect(response.dig("class")).to eq("Question")
end

context "when auto_tenant_creation passed" do
before do
@captured_request = nil
allow_any_instance_of(Faraday::Connection).to receive(:post) do |_, path, &block|
expect(path).to eq("schema")
req = OpenStruct.new(body: {})
block.call(req)
@captured_request = req
response
end
end
Comment on lines +81 to +90
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VCR or WebMock would simplify this a ton, but this is essentially grabbing the req object yielded to Faraday so we can check that multiTenancyConfig is set up correctly.


it "sets up multiTenancyConfig with autoTenantCreation and autoTenantActivation enabled" do
schema.create(
class_name: "Question",
description: "Information from a Jeopardy! question",
multi_tenant: true,
auto_tenant_creation: true,
auto_tenant_activation: true
)

expect(@captured_request.body["multiTenancyConfig"]).to eq({ enabled: true, autoTenantCreation: true, autoTenantActivation: true })

Check failure on line 101 in spec/weaviate/schema_spec.rb

View workflow job for this annotation

GitHub Actions / tests (3.0)

Layout/SpaceInsideHashLiteralBraces: Space inside { detected.

Check failure on line 101 in spec/weaviate/schema_spec.rb

View workflow job for this annotation

GitHub Actions / tests (3.0)

Layout/SpaceInsideHashLiteralBraces: Space inside } detected.

Check failure on line 101 in spec/weaviate/schema_spec.rb

View workflow job for this annotation

GitHub Actions / tests (3.1)

Layout/SpaceInsideHashLiteralBraces: Space inside { detected.

Check failure on line 101 in spec/weaviate/schema_spec.rb

View workflow job for this annotation

GitHub Actions / tests (3.1)

Layout/SpaceInsideHashLiteralBraces: Space inside } detected.

Check failure on line 101 in spec/weaviate/schema_spec.rb

View workflow job for this annotation

GitHub Actions / tests (3.3)

Layout/SpaceInsideHashLiteralBraces: Space inside { detected.

Check failure on line 101 in spec/weaviate/schema_spec.rb

View workflow job for this annotation

GitHub Actions / tests (3.3)

Layout/SpaceInsideHashLiteralBraces: Space inside } detected.
end
end
end

describe "#delete" do
Expand Down
Loading