laminas/laminas-cache

Migration to PHP 8.0 with replace leads to unexpected errors

boesing opened this issue · 8 comments

The instruction worked for most of our projects.
But there was one project, which depended on multiple projects in which the replacement was done.

Adding replaces in the main project composer will throw the following error:

[root@ffc765ad176a html]# php -d memory_limit=8G composer.phar -W update
Loading composer repositories with package information
In Laminas\DependencyPlugin\DependencyRewriterV2::onPrePoolCreate
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - vendor/main-project is present at version dev-master and cannot be modified by Composer
    - Root composer.json requires vendor/sub-project-1 ^1.5 -> satisfiable by vendor/sub-project-1[v1.5.0].
    - vendor/sub-project-2[v1.4.0], vendor/sub-project-1[v1.5.0] cannot be installed as that would require removing vendor/main-project[dev-master]. They all replace laminas/laminas-cache-storage-adapter-apc and thus cannot coexist.
    - Root composer.json requires vendor/sub-project-2 ^1.4 -> satisfiable by vendor/sub-project-2[v1.4.0].

Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.

Without the replaces in the main project the following errors are thrown:

[root@ffc765ad176a html]# php -d memory_limit=8G composer.phar -W update
Loading composer repositories with package information
In Laminas\DependencyPlugin\DependencyRewriterV2::onPrePoolCreate
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires vendor/sub-project-1 ^1.5 -> satisfiable by vendor/sub-project-1[v1.5.0].
    - Only one of these can be installed: laminas/laminas-cache-storage-adapter-zend-server[1.0.0, 1.0.1], vendor/sub-project-2[v1.4.0], vendor/sub-project-1[v1.5.0]. [vendor/sub-project-2, vendor/sub-project-1] replace laminas/laminas-cache-storage-adapter-zend-server and thus cannot coexist with it.
    - Root composer.json requires vendor/sub-project-2 ^1.4 -> satisfiable by vendor/sub-project-2[v1.4.0].

Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.

Do you have any hints/ideas how we could circumnavigate this issue?
Would an "archived-projects" composer package which replaces all archived repos and require this in all the subprojects do the trick?
Are there any easier methods?

Originally posted by @plorenz-etes in #88 (comment)

Hey there,

without more specific information about the vendor/sub-project, there is no way to really help here.

  • Does the "sub project" directly require laminas/laminas-cache-storage-adapter-zend-server because it depends on that adapter? If so, there is absolutely no way to bump to PHP 8.0 as the zend-server adapter does not support PHP 8.0 due to the inability of verifying its functionality (zend-server is a paid product which we do not have as a container to run our tests on)
  • Did you replace laminas/laminas-cache-storage-adapter-zend-server explicitly and the error still appears?

Hey,

is laminas/laminas-cache-storage-adapter-apc really required? The dependency/project is already marked as abandoned and has a lock on php ^5.6 || ^7.0.

Error Message:

  Problem 1
    - doctrine/doctrine-module[4.2.0, ..., 4.2.x-dev] require laminas/laminas-cache ^2.13.0 -> satisfiable by laminas/laminas-cache[2.13.0, 2.13.1, 2.13.2, 2.13.x-dev].
    - laminas/laminas-cache[2.13.0, ..., 2.13.x-dev] require laminas/laminas-cache-storage-adapter-apc ^1.0 -> satisfiable by laminas/laminas-cache-storage-adapter-apc[1.0.0, 1.0.1, 1.0.x-dev, 1.1.x-dev].
    - laminas/laminas-cache-storage-adapter-apc[1.0.0, ..., 1.1.x-dev] require php ^5.6 || ^7.0 -> your php version (8.0.12) does not satisfy that requirement.
    - Root composer.json requires doctrine/doctrine-module ^4.2 -> satisfiable by doctrine/doctrine-module[4.2.0, 4.2.1, 4.2.x-dev].

Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.

Edit:
Found a workaround https://github.com/doctrine/DoctrineModule#note-on-php-80-or-later

@fourhundredfour

…is laminas/laminas-cache-storage-adapter-apc really required?

There is a misunderstanding because the apc adapter is not required!

(The underlying extension will never get an update for PHP 8 therefore the adapter is abandoned. The apcu adapter can be used as a replacement.)

Found a workaround https://github.com/doctrine/DoctrineModule#note-on-php-80-or-later

Please also have a look at the official installation instructions: https://docs.laminas.dev/laminas-cache/installation/#avoid-unused-cache-adapters-are-being-installed

I will try to get more into detail about the different projects and the problem.

We have a laminas/mezzio project, let's call it asdf/api. This project requires psr-7 compatible auth and acl projects, let's call them asdf/auth and asdf/acl.
All 3 projects require doctrine/doctrine-orm-module. doctrine/doctrine-orm-module depends on doctrine/doctrine-module which further depends on laminas/laminas-cache.

To get to PHP8 we updated asdf/auth and asdf/acl by adding the following replace snippet into the composer.json:

    "replace": {
        "laminas/laminas-cache-storage-adapter-apc": "*",
        "laminas/laminas-cache-storage-adapter-dba": "*",
        "laminas/laminas-cache-storage-adapter-memcached": "*",
        "laminas/laminas-cache-storage-adapter-mongodb": "*",
        "laminas/laminas-cache-storage-adapter-wincache": "*",
        "laminas/laminas-cache-storage-adapter-xcache": "*",
        "laminas/laminas-cache-storage-adapter-zend-server": "*"
    },

asdf/auth and asdf/acl could run composer update without errors and are now available with PHP8.

We also added the snippet into the asdf/api project. But here we ran into the error from the issue, since now composer has multiple project which all try to replace the same.

Perhaps this is an issue for doctrine/doctrine-module that they should replace the abandoned projects?

I hope this could give some insight into the issue.

@plorenz-etes so what won't work is that you have replace in multiple projects (as you see in your error message).
If you already have replace in vendor/sub-project-1, there is no need to add another replace in your root project.

However, only projects should replace packages temporarily (until v3 is being released - which will be this afternoon in CET timezone).

So if you have components like vendor/sub-project-1 (which supposed to be a component because projects requiring projects does not make sense to me as of now), these components should not replace anything.

However, I will release laminas-cache v3 now, so you can try to simply migrate to that version (if possible).
If not, run your vendor/sub-project-1 CI with --ignore-platform-req composer flag as of now.
As you've already found out, it is impossible to have multiple replacements for the same package in one project.

so what won't work is that you have replace in multiple projects (as you see in your error message).
If you already have replace in vendor/sub-project-1, there is no need to add another replace in your root project.

That's what I thought hence I also gave errors messages without the replaces in the root project.
The problem is/was that two sub-projects, auth and acl, needed the replace snippet since both individually required doctrine/doctrine-orm-module.

But since v3 is out now, I'll wait until the doctrine projects upgrade to this version and this will fix the underlying problem.
Should I close the issue, since the fix should be upgrading to version 3?

The problem is/was that two sub-projects, auth and acl, needed the replace snippet since both individually required doctrine/doctrine-orm-module.

Actually, no 3rd-party component does explicitly require dedicated storage adapters and thus, replacing them is only necessary in root projects not in consuming libraries.
No library should ever explictly require a specific adapter and thus there is no problem with doctrine/doctrine-orm-module.

So I am pretty sure that there is another issue in your projects dependency tree.


So the only properly working solution is

only replace components in your root composer.json - NEVER replace components in a composer.json you are somewhere require via another project


You could probably verify if some of your dependencies directly requires the zend-server storage adapter by executing composer why laminas/laminas-cache-storage-adapter-zend-server. But you should do that your project where you haven't applied any changes (yet).

Closing here as there was no update for quite a long time.
If you think this should be re-opened, feel free to comment on this issue.