Skip to content
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

cannot display Valkyrie Resource saved through new form - raises undefined method `model_name' for nil:NilClass #4559

Closed
elrayle opened this issue Oct 28, 2020 · 8 comments

Comments

@elrayle
Copy link
Contributor

elrayle commented Oct 28, 2020

Descriptive summary

Cannot display a valkyrie resource work that was created with the valkyrie based form. Note that the form may be working fine. I suspect it is something to do with the structure of the resource or the change set that is generated for the resource.

Rationale

Valkyrie Resources should work with save and display.

Expected behavior

Attempting to display a valkyrie resource on the show view after it is created through the valkyrie based form should show the valkyrie resource work with the values set and saved in the new form.

Actual behavior

Attempting to display a valkyrie resource on the show view after it is created through the valkyrie based form raises an exception.

Steps to reproduce the behavior

  1. Create a monograph work using http://localhost:3000/concern/monographs/new
  2. Fill in required info and Save

When it forwards to the display page after saving, it raises undefined method 'model_name' for nil:NilClass in app/models/concerns/hyrax/solr_document_behavior.rb.

I haven't completely traced this, but it appears to have something to do with permissions and missing attribute admin_set.

@elrayle
Copy link
Contributor Author

elrayle commented Oct 28, 2020

I can read and write with pure valkyrie calls.

This works to save the resource...

m = Monograph.new                                  # create a new monograph
mcs = Hyrax::ChangeSet.for(m)                      # create a change set for the new monograph
mcs.title = 'My Monograph'                         # set a title
mcs.admin_set_id = 'admin_set/default'             # set the admin set
mid = Hyrax.persister.save(resource: mcs.sync).id  # sync the change set and save the resource
mr = Hyrax.query_service.find_by(id: "2227mp645")  # does find the resource

But if I try to display the saved resource in Hyrax internal app, I get the same error as described in the issue above.

http://localhost:3000/concern/monographs/2227mp645?locale=en

Raises undefined method 'model_name' for nil:NilClass


Hyrax uses the CreateWork transaction to save the work from the form. Trying that in rails console fails to save the work...

m = Monograph.new                                  # create a new monograph
mcs = Hyrax::ChangeSet.for(m)                      # create a change set for the new monograph
mcs.title = 'My Monograph'                         # set a title
mcs.admin_set_id = 'admin_set/default'             # set the admin set
Hyrax::Transactions::CreateWork.new.call(mcs) # use transaction to save

Raises undefined method 'admin_set'

@elrayle
Copy link
Contributor Author

elrayle commented Oct 28, 2020

If I add a method to the change set that returns the admin set, I get past the error thrown by running the transaction. But this only leads me to another error...

NoMethodError (undefined method 'edit_groups' for #<#<Class:0x00007fea6ab92f38>:0x00007fea6abc8278>)

@no-reply
Copy link
Member

@elrayle the issue with Hyrax::Transactions::CreateWork is that this is a legacy transaction for AF objects, not a valkyrie/changeset transaction.

the easiest way to avoid this pitfall is to always use the Container interface for resolving transaction names Hyrax::Transactions::Container['change_set.create_work'] is the transaction you want.

consistently using this interface will also help ensure that intended customizations are applied uniformly.

@dunn
Copy link
Contributor

dunn commented Nov 16, 2020

i get a different error entirely when i try to create the work via the form:

value! was called on Failure(["undefined method `permissions' for #<#<Class:0x0000561aa62a7e18>:0x0000561aa61fd828>

called from

/app/samvera/hyrax-engine/app/controllers/concerns/hyrax/works_controller_behavior.rb:191:in `create_work'
/app/samvera/hyrax-engine/app/controllers/concerns/hyrax/works_controller_behavior.rb:58:in `create'

@elrayle
Copy link
Contributor Author

elrayle commented Nov 17, 2020

Retrying with the suggested change to transaction does save the work...

m = Monograph.new                                  # create a new monograph
mcs = Hyrax::ChangeSet.for(m)                      # create a change set for the new monograph
mcs.title = 'My Monograph'                         # set a title
mcs.admin_set_id = 'admin_set/default'             # set the admin set
m_updated = Hyrax::Transactions::Container['change_set.create_work'].call(mcs).value! # use transaction to save

m_read_in = Hyrax.query_service.find_by(id: m_updated.id)
m_read_in.title                                    # ['My Monograph']

elrayle added a commit that referenced this issue Nov 17, 2020
Also…
* makes sure all tests are using Monograph which is a Valkyrie resource work
* comments out places that are subject to error described in Issue #4559
elrayle added a commit that referenced this issue Nov 17, 2020
Also…
* makes sure all tests are using Monograph which is a Valkyrie resource work
* comments out places that are subject to error described in Issue #4559
elrayle added a commit that referenced this issue Nov 17, 2020
Also…
* makes sure all tests are using Monograph which is a Valkyrie resource work
* comments out places that are subject to error described in Issue #4559
elrayle added a commit that referenced this issue Nov 17, 2020
Also…
* makes sure all tests are using Monograph which is a Valkyrie resource work
* comments out places that are subject to error described in Issue #4559
elrayle added a commit that referenced this issue Nov 17, 2020
This is to make rubocop happy with a kludge for issue #4559
elrayle added a commit that referenced this issue Nov 18, 2020
This is to make rubocop happy with a kludge for issue #4559

rc

rc
elrayle added a commit that referenced this issue Nov 18, 2020
Also…
* makes sure all tests are using Monograph which is a Valkyrie resource work
* comments out places that are subject to error described in Issue #4559
elrayle added a commit that referenced this issue Nov 18, 2020
This is to make rubocop happy with a kludge for issue #4559

rc

rc
@elrayle
Copy link
Contributor Author

elrayle commented Nov 18, 2020

In debugging, we can see...

  • breaking in populator, permissions is empty if we don't change permissions on the share page
  • if we share the work with a user on the share tab, we get an error [Reform] Your :populator did not return a Reform::Form instance for 'permissions'

Looking at the form, the permissions are stored in field monograph['permissions_attributes'][0][name|type|access]

We tried reworking the collection :permissions in ResourceForm to be collection :permissions_attributes but this caused even more errors when trying to enter the form.

We weren't able to locate exactly where the code that sets permissions in the form for AF objects was located to see if we could connect the AF process to the Resource process.

@no-reply
Copy link
Member

is this one cleared? on my local (dassie) i'm able to create a work with the Monograph work type and have it display without errors.

@no-reply no-reply removed the bug label Mar 18, 2021
@elrayle
Copy link
Contributor Author

elrayle commented Apr 26, 2021

Tested with latest master and the forward happens without error. Closing.

@elrayle elrayle closed this as completed Apr 26, 2021
@elrayle elrayle moved this from Ready to Archive in Hyrax-Valkyrization Apr 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Hyrax-Valkyrization
Ready to be Archived
Development

No branches or pull requests

3 participants