Solved

Adding dataset with Ruby SDK

  • 20 April 2023
  • 5 replies
  • 56 views

  • Known Participant
  • 18 replies

Hello!

I have an issue with using Ruby SDK to add a dataset to a project.

I’m following those docs: https://sdk.gooddata.com/gooddata-ruby-doc/docs/advanced_blueprint_examples#playing-with-computed-attributes with sample code like below

blueprint = project.blueprint

update = GoodData::Model::ProjectBlueprint.build('update') do |p|
p.add_dataset('dataset.mynewdataset') do |d|
d.add_anchor(...)
d.add_attribute(attribute_id, title: attribute_title)
# other attributes
end
end

new_blueprint = blueprint.merge(update)
project.update_from_blueprint(new_blueprint)

But every time I’m getting an error saying, that some object already exists, each time giving a different object id for the original blueprint. So it looks like it was trying to duplicate already existing objects instead of only adding a new dataset. I see there’s an option to pass update preference, but I don’t want to allow cascade drops as I don’t want to risk loosing current data model. 

Do you have any suggestions on what I may be doing wrong?

 

Best,

Hanna

icon

Best answer by Anonymous 28 April 2023, 15:23

View original

5 replies

Hello Hanna!

This is Marek from Technical Support Team. Thank you for reaching out with this.

I will go ahead and replicate the issue you are having with this code sample and reach back to you once I figure out what is going on here.

Best,

Marek

 

Hi again!

I looked into this and it seems that some of the datasets in the original blueprint have the same ID as the new dataset you are trying to add, which is why are you seeing these errors. Another possibility is that you are using already existing attribute/fact identifiers, which are unique per workspace.

Would it please be possible to share the full error message that is being raised (you can obfuscate the actual IDs)?

You might try this instead (as taken from the example from our docs):

blueprint = project.blueprint

update = GoodData::Model::ProjectBlueprint.build('update') do |p|
p.add_dataset('dataset.mynewdataset') do |d|
d.add_anchor('attr.users.id', title: 'Users ID', folder: 'Users ID folder')
d.add_label('label.users.id_label1', reference: 'attr.users.id')
d.add_label('label.users.id_label2', reference: 'attr.users.id', default_label: true)
d.add_attribute('attr.users.another_attr', title: 'Another attr')
d.add_label('label.users.another_attr_label', reference: 'attr.users.another_attr')
d.add_fact('fact.users.some_number')
# other attributes
end
end

new_blueprint = blueprint.merge(update)

project.update_from_blueprint(new_blueprint)

Please let us know if this helps.

Also, you can always run a validate() method on the blueprint before calling update_from_blueprint() to ensure the blueprint is indeed valid. 

Thank you!
Marek

Hello, so I double checked and unfortunately I still have the same issue.

Here’s my additional test dataset I want to add:

update = GoodData::Model::ProjectBlueprint.build('update') do |p|
p.add_dataset('dataset.mynewdataset') do |d|
d.add_anchor('attr.mynewdataset.id', title: 'Users ID', folder: 'My new dataset')
d.add_label('label.mynewdataset.id_label1', reference: 'attr.mynewdataset.id')
d.add_label('label.mynewdataset.id_label2', reference: 'attr.mynewdataset.id', default_label: true)
d.add_attribute('attr.mynewdataset.another_attr', title: 'Another attr')
d.add_label('label.mynewdataset.another_attr_label', reference: 'attr.mynewdataset.another_attr')
d.add_fact('fact.mynewdataset.some_number')
# other attributes
end
end

new_blueprint = blueprint.merge(update)

project.update_from_blueprint(new_blueprint)

Validation returned an empty array. The error I get is GoodData::MaqlExecutionError (Unable to migrate LDM, reason(s): )
 Object 'attr.project.projectcustomtextfield1' already exists

Where `attr.project.projectcustomtextfield1` is indeed already existing id but it’s not in my update. After running `udpate_from_blueprint` whole MAQL was displayed and there were a lot of ALTER DATASET but also CREATE FACT and CREATE ATTRIBUTE definitions referring already existing fields in the original blueprint. 

Can it be some setting on the workspace that causes such behaviour? It was generated by cloning from production account, but normally we’re using provision/release/rollout lifecycle.

 

Best,

Hanna

I’ve actually made one another test and updated blueprint for my template workspace, and for that one the update went without issues. So I suppose there is something about my workspace config that causes the problem

Hi Hanka,

Thank you for the clarification! If the cloned workspace came from a workspace that is managed by LCM (provision/release/rollout lifecycle), it is most likely caused by the metadata flag `_lcm_managed_object:true`. Essentially, all metadata elements managed by LCM are tagged with this flag, which might cause some unexpected behavior, as objects tagged with this flag cannot be manipulated.

Could you please check whether the original project blueprint’s metadata had such flags? You can find it in the metadata object’s grey page. The best way to get there is to use our GoodData Chrome Extension tool (available here, more information here).

You can check it like this:

Best,

Marek

Reply