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

FIX: Update model class importer key #1743

Conversation

mikenuguid
Copy link
Contributor

@mikenuguid mikenuguid commented May 8, 2024

Description

Using a custom URL slug throws an exception due to non-existing key equivalent to the model class. Using model tab solves this since it utilises either the custom url slug or the fully-qualified name of the class as key on the model importers.

This fixes the undefined array key exception e.g. [Warning] Undefined array key "Sheadawson\Linkable\Models\Link" seen when importing on a model admin with a custom URL slug.

This should not have any regressions on model admins without custom slug.

Code clean-up on a test suite.

Manual testing steps

With custom url slug

  1. Add a model admin and model class e.g.: ContactAdmin and Contact (model admin and model, respectively).

  2. Assign a custom slug to the model admin e.g.:

    class ContactAdmin extends ModelAdmin
    {
        private static $url_segment = 'contactadmin';
    
        private static $managed_models = [
           'contacts' => [
                'dataClass' => Contact::class,
                'title' => 'Contacts',
            ]
        ];
    
    // ...
    }
  3. Once setup and viewable on the CMS, go to the ContactAdmin landing page on the CMS and import a file to populate the model. (Note: this can also be done by pre-populating the model and exporting the records as .csv file then re-uploading the same file via import)

  4. Import should not cause any exception.

Without custom url slug

Follow same steps above but do not assign a custom slug to the model admin i.e.

class ContactAdmin extends ModelAdmin
{
    private static $url_segment = 'contactadmin';

    private static $managed_models = [
       Contact::class,
    ];

//...
}

Using the import form should not generate any errors.

Issues

Pull request checklist

  • The target branch is correct
  • All commits are relevant to the purpose of the PR (e.g. no debug statements, unrelated refactoring, or arbitrary linting)
    • Small amounts of additional linting are usually okay, but if it makes it hard to concentrate on the relevant changes, ask for the unrelated changes to be reverted, and submitted as a separate PR.
  • The commit messages follow our commit message guidelines
  • The PR follows our contribution guidelines
  • Code changes follow our coding conventions
  • This change is covered with tests (or tests aren't necessary for this change)
  • Any relevant User Help/Developer documentation is updated; for impactful changes, information is added to the changelog for the intended release
  • CI is green

@GuySartorelli
Copy link
Member

CMS 4 has entered its security-only support phase, and won't be getting any new patch releases. Please target the 2.2 branch (assuming this affects CMS 5)

@mikenuguid
Copy link
Contributor Author

Is it fine to re-use the same branch name (and target 2.2)? Or do I need to create a new pull request?

@GuySartorelli
Copy link
Member

GuySartorelli commented May 8, 2024

If you retarget to 2.2 and there are more commits than your original one displayed at the top of the PR, you may need to reset your commits - but you don't have to make a new PR unless that's easier for you.

@mikenuguid mikenuguid force-pushed the pulls/1.13/fix-model-admin-import branch from fe80854 to efc9f08 Compare May 8, 2024 22:04
@mikenuguid mikenuguid changed the base branch from 1.13 to 2.2 May 8, 2024 22:04
@mikenuguid mikenuguid marked this pull request as ready for review May 8, 2024 23:21
@mikenuguid
Copy link
Contributor Author

Marked this ready for review but some jobs on workflow still failing, do I need to re-run them until green?

@GuySartorelli
Copy link
Member

CI is green here: https://github.com/silverstripe/silverstripe-admin/actions/runs/9008788626
But it's not appearing in this PR for some reason, which is concerning. Can you please force a push so CI shows up correctly? Sometimes GitHub needs a nudge.

You can force a push without making any changes by running git commit --amend --no-edit && git push --force-with-lease

- using a custom URL slug throws exception due to non-existing key equivalent to the model class. Using model tab solves this since it utilises either the custom url slug or the fully-qualified name(FQN) of the class.
@mikenuguid mikenuguid force-pushed the pulls/1.13/fix-model-admin-import branch from efc9f08 to 78eb177 Compare May 8, 2024 23:55
Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

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

Works well locally. Looks like there's no unit test for the import() method so I won't ask you to add that now.

Thank you for implementing this fix

@GuySartorelli GuySartorelli merged commit 6925ecb into silverstripe:2.2 May 9, 2024
12 checks passed
@GuySartorelli GuySartorelli deleted the pulls/1.13/fix-model-admin-import branch May 9, 2024 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants