Skip to content

Correctly return int values where required. #26930

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 15 commits into from
Closed

Correctly return int values where required. #26930

wants to merge 15 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Feb 19, 2020

Related Pull Requests

https://github.com/magento/partners-magento2ee/pull/159
https://github.com/magento/partners-magento2b2b/pull/61

Description (*)

The methods getCustomerId and getCustomerGroupId incorrectly return strings due to the usage of getData. This PR casts the values to ints, to match the return type hints.

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)
  • All automated tests passed successfully (all builds are green)

@m2-assistant
Copy link

m2-assistant bot commented Feb 19, 2020

Hi @paul-gene. Thank you for your contribution
Here is 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

For more details, please, review the Magento Contributor Guide documentation.

Copy link
Contributor

@ihor-sviziev ihor-sviziev left a comment

Choose a reason for hiding this comment

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

@paul-gene,
Your changes looks good, however there are some test failures, looks like your changes broke something.
Could you fix found issues?

@ihor-sviziev ihor-sviziev self-assigned this Feb 20, 2020
@ghost ghost dismissed ihor-sviziev’s stale review February 20, 2020 06:42

Pull Request state was updated. Re-review required.

@ihor-sviziev ihor-sviziev self-requested a review February 20, 2020 06:47
@ghost
Copy link
Author

ghost commented Feb 20, 2020

@ihor-sviziev are the tests failing due to my actual code change?

@ihor-sviziev
Copy link
Contributor

@paul-gene seems like yes, but let’s restart failing tests, maybe it was some issue with testing infra
@magento run Functional Tests B2B, Functional Tests CE, Functional Tests EE, Integration Tests

@ghost
Copy link
Author

ghost commented Feb 20, 2020

@ihor-sviziev If my code change is the cause for failing tests, then the problem is bigger than I thought, as it means tests were written to be broken from the start. fml.

Can the tests be re-run without a commit to kick them into action?

@ihor-sviziev
Copy link
Contributor

@paul-gene TBH it's not seems the change chat could break functionality, but it might in not obvious way. All functional and integration tests are running all the time for all PRs, and I didn't saw that these tests were failing somewhere else.

@ghost
Copy link
Author

ghost commented Feb 20, 2020

@ihor-sviziev I can see a few PRs around the same time as mine that are failing the same tests.

@ghost
Copy link
Author

ghost commented Feb 20, 2020

@magento-engcom-team
Copy link
Contributor

Hi @VladimirZaets, thank you for the review.
ENGCOM-6947 has been created to process this Pull Request
✳️ @VladimirZaets, could you please add one of the following labels to the Pull Request?

Label Description
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests
Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests
Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests

@magento-engcom-team
Copy link
Contributor

@paul-gene thank you for contributing. Please accept Community Contributors team invitation here to gain extended permissions for this repository.

@ghost
Copy link
Author

ghost commented Feb 20, 2020

@VladimirZaets what's the next step to get this merged?

@ghost
Copy link
Author

ghost commented Feb 24, 2020

@magento run Functional Tests B2B, Functional Tests CE, Functional Tests EE, Integration Tests

@ihor-sviziev
Copy link
Contributor

@magento run Functional Tests B2B, Functional Tests CE, Functional Tests EE, Integration Tests

@paul-gene this command available only for maintainers

@ghost
Copy link
Author

ghost commented Feb 25, 2020

Thanks @ihor-sviziev

Are you able to explain this though? -#26930 (comment)

From what I can tell (allure is terrible to read), there is no possible way my code change could be breaking some of those tests.

@ihor-sviziev
Copy link
Contributor

@magento give me test instance

@magento-engcom-team
Copy link
Contributor

Hi @ihor-sviziev. Thank you for your request. I'm working on Magento instance for you

Copy link
Member

@slavvka slavvka left a comment

Choose a reason for hiding this comment

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

@paul-gene Unfortunately we have an error in our performance sanity check. For some reason opening the customer edit page fails:

1587742244099,240,Edit Customer (Admin Customer Management),200,OK,One Thread Scenarios Pool 5-1,text,false,Response was null,112515,0,1,1,http://localhost/builds/backend/customer/index/edit/id/1/,236,0,0

Could you please check what is the reason of that. You need to run jMeter scenario against your code (sanity (3).zip).

More information you can find here https://github.com/magento/magento2ce/tree/2.4-develop/setup/performance-toolkit. There's a mistake in there, you need to take 3rd version

@ghost ghost assigned slavvka Apr 24, 2020
@ghost ghost dismissed stale reviews from ihor-sviziev and Nazar65 April 24, 2020 18:09

Pull Request state was updated. Re-review required.

@ghost ghost requested review from slavvka, Nazar65 and ihor-sviziev April 27, 2020 08:25
@ihor-sviziev
Copy link
Contributor

Hi @paul-gene,
I don't see any changes, so not sure we do have something to review. Maybe you missed to push your changes?

@ghost
Copy link
Author

ghost commented Apr 27, 2020

@ihor-sviziev honestly, I don't understand any of @slavvka 's comment.

Everything was approved and all tests passed, so how all of a sudden did something break?

@ihor-sviziev
Copy link
Contributor

ihor-sviziev commented Apr 27, 2020

@paul-gene your changes looks good, but we during running performance tests we found performance degradation in one specific case (that @slavvka described above). You could reproduce it by running attached jMeter profile from and compare changes from your PR with 2.4-develop branch.

This is one of the last steps before merging PR, that's why it happened.

Unfortunately we should strong motivation for accepting PRs that introduce performance degradation, while this PR don't have such, so it seems like PR should be adjusted.

Hope you got my point. If you have any questions

BTW I found that in comment above we have incorrect link, here is correct one https://github.com/magento/magento2/tree/2.4-develop/setup/performance-toolkit

@ghost
Copy link
Author

ghost commented Apr 27, 2020

@ihor-sviziev I'll be honest, a lot of work was done after my initial commits, and I've never heard of, or used, jMeter.

I'm not sure I believe that casting variables to integers would degrade performance enough for it to make any conceivable difference, if at all :/

@slavvka
Copy link
Member

slavvka commented Apr 27, 2020

@engcom-Echo could you please help @paul-gene find out what's wrong with the PAT Sanity scenario?

@ihor-sviziev ihor-sviziev added the Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. label Apr 28, 2020
@ihor-sviziev
Copy link
Contributor

@magento run all tests

Copy link
Contributor

@orlangur orlangur left a comment

Choose a reason for hiding this comment

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

Please provide test scenarios in which returning int is required (i.e. broken functionality).

int type hint covers both integers and numeric strings in fact.

See #14057 (comment) for more details.

@orlangur orlangur requested a review from VladimirZaets May 5, 2020 08:32
@ghost ghost assigned orlangur May 5, 2020
@ihor-sviziev
Copy link
Contributor

ihor-sviziev commented May 18, 2020

Hi @orlangur,
Will copy my response here (from #10519 (comment)):

Issue appears when you're using strict types declare(strict_types=1) in your file. Then you expect that if value should be int - you can use it for your method that has declaration like this

<?php
declare(strict_types=1);

function myFunction(int $storeId): void
{
}

$storeId = '2'; // let's assume we executed $store->getId(); that has defined return type int
myFunction($storeId);

output of php 1.php:

PHP Fatal error:  Uncaught TypeError: Argument 1 passed to myFunction() must be of the type integer, string given, called in /home/ihor/1.php on line 7 and defined in /home/ihor/1.php:3
Stack trace:
#0 /home/ihor/1.php(7): myFunction('2')
#1 {main}
  thrown in /home/ihor/1.php on line 3

In this case you'll get type error. Why - because string !== int.

@ghost ghost requested a review from orlangur May 18, 2020 14:00
@ihor-sviziev ihor-sviziev removed their assignment May 25, 2020
@orlangur
Copy link
Contributor

@ihor-sviziev this code is incorrect, we cannot rely on types derived from files without strict types declaration.

@paul-gene as per discussion in maintainers chat I'm closing this PR. We must use strict types in all new code, however, we have too many numeric strings in legacy code and any such change may cause bugs.

@orlangur orlangur closed this May 29, 2020
@m2-assistant
Copy link

m2-assistant bot commented May 29, 2020

Hi @paul-gene, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests Component: Customer Component: Quote Component: Wishlist Progress: needs update Release Line: 2.4 Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants