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

Add compatibility with the Symfony 4.4 VarExporter #10948

Merged
merged 1 commit into from
Dec 1, 2023

Conversation

cmodijk
Copy link
Contributor

@cmodijk cmodijk commented Sep 15, 2023

This issue tries to solve the weird Symfony __unserialize data Symfony 4.4 is giving to the method. This seems to be a bug that Symfony solved in 5.4 in symfony/symfony@6ccb85e. Original report / investigation #10943.

greg0ire
greg0ire previously approved these changes Sep 15, 2023
@derrabus
Copy link
Member

Is there a way we can test this? 🤔

Also, can we revert this change on 3.0.x?

@greg0ire
Copy link
Member

Is there a way we can test this? 🤔

In #10684, you introduced txt files containing serialized data. Maybe there should be a new text file with the 3rd format in it?

@cmodijk
Copy link
Contributor Author

cmodijk commented Sep 20, 2023

Is there a way we can test this? 🤔

The txt files containing serialized data was not really working for me as Symfony directly call's the __unserialize with the wrong formated data. So i added a new test instead to check if that mapped data is handled.

Also, can we revert this change on 3.0.x?

I'm not sure. If 3.0.x is removing support for Symfony 4.4 then yes. In the end it depends on if Doctrine ORM whants to support Symfony 4.4. When Symfony 4.4 support is dropped then this can be removed.

But maybe the whole __unserialize should be dropped at some point as it still tries to reflect the old data from version 2.14.3 and when the __unserialize method is not there Symfony 4.4 also work's as expected.

@derrabus
Copy link
Member

I'm not sure. If 3.0.x is removing support for Symfony 4.4 then yes.

Symfony 4.4 is EOL, so yes, we won't support it on the 3.0.x branch.

@derrabus
Copy link
Member

Can we actually use VarExporter in that test? Otherwise nobody will understand where that data structure is coming from.

@cmodijk
Copy link
Contributor Author

cmodijk commented Sep 25, 2023

Can we actually use VarExporter in that test? Otherwise nobody will understand where that data structure is coming from.

If there is a way to ensure we get the Symfony 4.4 version of the VarExporter in that test then yes. But I don't know how i could achief that. For context to @derrabus this seems to be fixed in Symfony 5.4 and higher.

@derrabus
Copy link
Member

We do run our tests against VarExporter 4.4, yes.

@cmodijk
Copy link
Contributor Author

cmodijk commented Oct 12, 2023

@derrabus I have checked out the PHPUnit check but can't firure out where Symfony 4.4 is tested?

@greg0ire
Copy link
Member

@cmodijk
Copy link
Contributor Author

cmodijk commented Oct 19, 2023

I have rewriten the test to only validate it when symfony/var-exporter versie 4.4 is used and then let it export the data and then unserialize it back to the prefered data. Would love to hear feedback if this is a correct way of testing this.

@cmodijk cmodijk force-pushed the bug-10943 branch 2 times, most recently from a936549 to 0966b3d Compare October 19, 2023 12:15
@derrabus
Copy link
Member

I have rewriten the test to only validate it when symfony/var-exporter versie 4.4 is used

Why? I understand that the problem is only reproducible with VarExporter 4, but the test should pass with any version, shouldn't it?

@cmodijk
Copy link
Contributor Author

cmodijk commented Oct 20, 2023

Why? I understand that the problem is only reproducible with VarExporter 4, but the test should pass with any version, shouldn't it?

Yes, you are right did not think about that. I removed the skip.

Comment on lines 80 to 82
$data = file_put_contents($tempFile, '<?php return ' . $exported . ';');

$unserialized = require $tempFile;
Copy link
Member

Choose a reason for hiding this comment

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

This is a complicated way to perform an eval(), isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure how i can solve this i followd the Symfony docs which has noted it to use it this way.

use Symfony\Component\VarExporter\VarExporter;

$exported = VarExporter::export($someVariable);
// store the $exported data in some file or cache system for later reuse
$data = file_put_contents('exported.php', '<?php return '.$exported.';');

// later, regenerate the original variable when you need it
$regeneratedVariable = require 'exported.php';

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What we maybe could do is dump the file once, commit it and then use the output to validate. But then we still need a way to import the file which is the part your question is about. So maybe this is still not the way. 🤔

Copy link
Member

Choose a reason for hiding this comment

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

You don't need a file. PHP has eval(). Use that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have pushed a update to use eval instead.

@cmodijk
Copy link
Contributor Author

cmodijk commented Dec 1, 2023

@derrabus I have updated the code with the feedback. When you have time can you check if this is what you expected?

derrabus
derrabus previously approved these changes Dec 1, 2023
@derrabus derrabus added this to the 2.17.2 milestone Dec 1, 2023
@derrabus derrabus changed the base branch from 2.16.x to 2.17.x December 1, 2023 16:24
@derrabus derrabus dismissed their stale review December 1, 2023 16:24

The base branch was changed.

@derrabus derrabus merged commit 23d36c0 into doctrine:2.17.x Dec 1, 2023
58 checks passed
@derrabus
Copy link
Member

derrabus commented Dec 1, 2023

Thank you!

@cafferata
Copy link

Thank you too!

derrabus added a commit that referenced this pull request Dec 1, 2023
* 2.18.x:
  Add compatibility with the Symfony 4.4 VarExporter (#10948)
  PHPStan 5.16.0, Symfony 7.0 (#11095)
@cmodijk
Copy link
Contributor Author

cmodijk commented Dec 4, 2023

Yes, Thank you too! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants