Skip to content

Issue #35676 Model/Import/Entity/AbstractEntity restricts import column names to a-z (lowercase) #35859

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

Closed
wants to merge 2 commits into from

Conversation

artskirk
Copy link

@artskirk artskirk commented Aug 2, 2022

Description (*)

Model/Import/Entity/AbstractEntity restricts import column names to a-z (lowercase), 0-9 or underscore and must start with a-z (lowercase). In that case if you are trying to import file with new column name like Sku_1 it fails with error.

image

  • Open app/code/Magento/Catalog/etc/db_schema.xml and add a new column with name Sku_1
  • Run bin/magento setup:upgrade. This will create a new column with name Sku_1 in table catalog_product_entity.
  • Try to upload the CSV by adding newly created column in the CSV file from admin->System->Data Transfer->Import
  • The script will fail for the newly created column

What I did
I have updated column validation regular expression to be more flexible.

Related Pull Requests

Fixed Issues (if relevant)

  1. Fixes Remove import column name character restrictions #35676

Manual testing scenarios (*)

  1. Open app/code/Magento/Catalog/etc/db_schema.xml and add a new column with name Sku_1
  2. Run bin/magento setup:upgrade. This will create a new column with name Sku_1 in table catalog_product_entity.
  3. Try to upload the CSV by adding newly created column in the CSV file from admin->System->Data Transfer->Import
  4. The script works without validation errors

Questions or comments

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)

@m2-assistant
Copy link

m2-assistant bot commented Aug 2, 2022

Hi @artskirk. Thank you for your contribution
Here are some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names. Allowed build names are:

  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE,
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here

ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review.

For more details, review the Magento Contributor Guide documentation.

⚠️ According to the Magento Contribution requirements, all Pull Requests must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 The triage of Pull Requests happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@m2-community-project m2-community-project bot added Priority: P3 May be fixed according to the position in the backlog. Progress: pending review labels Aug 2, 2022
@Den4ik
Copy link
Contributor

Den4ik commented Aug 5, 2022

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@Den4ik Den4ik self-assigned this Aug 5, 2022
@Den4ik Den4ik self-requested a review August 5, 2022 11:20
@Den4ik Den4ik added the Auto-Tests: Covered All changes in Pull Request is covered by auto-tests label Aug 5, 2022
@Den4ik
Copy link
Contributor

Den4ik commented Aug 5, 2022

@magento run Functional Tests B2B

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@Den4ik
Copy link
Contributor

Den4ik commented Aug 5, 2022

@magento give me 2.4-develop instance

@magento-deployment-service
Copy link

Hi @Den4ik. Thank you for your request. I'm working on Magento instance for you.

@magento-deployment-service
Copy link

Copy link
Contributor

@Den4ik Den4ik left a comment

Choose a reason for hiding this comment

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

Hey @artskirk
I have checked your changes and unfortunately could not agree with it by next reasons:

  1. \w mean any word character and is equal to [a-zA-Z0-9_]
  2. In fact you should create attribute with static type that will add column into entity table
  3. I'm not sure that uppercase characters is as good idea for using in the attribute codes
  4. Attribute code should start from [a-z]. Your expression allow start from digit or _
  5. If you try to add attribute from admin panel with code start with _ it will be trimmed.
  6. If you try to add attribute from admin panel with code start digit attr_ prefix will be added automatically

So I don't see any problems with current logic.
@sidolov Please correct me if I'm wrong

@hostep
Copy link
Contributor

hostep commented Aug 10, 2022

@Den4ik: from my testing, I was able to create an attribute with code Sku_1 using the backoffice of Magento. So if you then want to import products using this code as a column, it should be supported, right?

I agree with most of your other remarks though. The suggested regex changes aren't correct indeed.

This is the validation message you get in the backoffice when trying to create an invalid attribute code:

Please use only letters (a-z or A-Z), numbers (0-9) or underscore (_) in this field, and the first character should be a letter.

So I think the regex should be changed to /^[a-zA-Z][a-z0-9_]*$/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Priority: P3 May be fixed according to the position in the backlog.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove import column name character restrictions
3 participants