mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
DOMDocument schemaValidate error migrating to PHP 8.2 #7278
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @yard-mschwartz on GitHub (Dec 13, 2023).
BC Break Report
Summary
Currently upgrading one our projects to PHP 8.2 from PHP 7.4. Application runs fine on PHP 7.4 with
doctrine/ormalready on 2.17.1. However, when I bump the PHP-version to^8.2and runcomposer upgrade, the subsequentsymfony console cache:clearfails with anWarning: DOMDocument::schemaValidate(): Invalid Schemaerror.Previous behavior
The commands
symfony console cache:clearworks just fine.Current behavior
When I bump the PHP-version to
^8.2and runcomposer upgrade, the subsequentsymfony console cache:clearfails with the following error:Line 1006 is the
schemaValidate()in the following code block in[...]/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php:When I dump the
$filethat's being processed, it outputs[...]/vendor/friendsofsymfony/user-bundle/Resources/config/doctrine-mapping/User.orm.xml. So you might think this problem is related to that particular bundle, where I also created an issue, however that packages also didn't change versions during the version bump to PHP 8.2. Bothdoctrine/ormandfriendsofsymfony/user-bundlewere already on the latest version.I messed around a little bit, to see if I could get some more info on the error. If I change the first line of that code block to
$backedUpErrorSetting = libxml_use_internal_errors(false);, it shows a bit more information:I assume I have an error somewhere in my model definition, that somehow was acceptable before the upgrade, but I have a hard time pinpointing where that might be. The
friendsofsymfony/user-bundlefile looks fine, and also works fine in another project we upgraded to PHP 8.2.EDIT package overview and User model removed, because in the end they had nothing to do with this issue
Any suggestions?
@greg0ire commented on GitHub (Dec 13, 2023):
Hi! 👋 After reading this, I think I should have added an
@. Can you try restoring the code to its initial state then adding an@, like so:After that, you should get a detailed error message.
@mleko64 commented on GitHub (Dec 13, 2023):
I had the same problem after updating PHP 8.1 to 8.1.26. With this PHP update, the libxml2 library was also updated to version 2.12.2. After downgrading the libxml2 library to version 2.11.5, the problem has gone. I suppose two scenarios:
@yard-mschwartz commented on GitHub (Dec 13, 2023):
Hi @greg0ire . If I add the
@-sign, thesymfony console cache:clearcommand finishes normally as expected. No errors come up.Hi @mleko64 . I think you are right. A colleague of mine doesn't experience the same problem as I do. It appears we have different libxml versions.
Mine (on Linux Manjaro):
His (on a Mac):
@greg0ire commented on GitHub (Dec 13, 2023):
Can you work on taking Doctrine out of the equation? This looks like a libxml bug. The behavior I expect when setting
libxml_use_internal_errorstotrueis:libxml_get_errors@yard-mschwartz commented on GitHub (Dec 13, 2023):
I've been investigating a bit more, because this problem comes up for me in one project, but not in another. Let's call these two projects A and B respectively. I've been adding/removing packages in the two projects in order to synchronize them more.
What I discovered is that it seems to revolve around the
doctrine/annotationspackage. It needs to be on v2."doctrine/annotations": "^1.6". Project B doesn't include it, but uses v2 implicitly. When I add this line to Project B, it starts show theInvalid schemaerror"doctrine/annotations": "^1.6"from Project A, nothing changes. However, once I bumpnelmio/api-doc-bundlefrom^3to^4the problem is solved. Turns out v3 requires"doctrine/annotations": "^1.2", whereas v4 requires"doctrine/annotations": "^1.11|^2.0"So while I suspect libxml is in a way involved, correctly defining and updating my packages also seems to solve things.
@yard-mschwartz commented on GitHub (Dec 13, 2023):
Not sure what is going on anymore. I did the above procedure with 90% of my project deleted. When I apply it to the full project, the
Invalid Schemawarning is back. My brain hurts and I should probably take a break. 😅@yard-mschwartz commented on GitHub (Dec 13, 2023):
@greg0ire I tried as you said
Created a little sandbox project with the following files:
index.phpas belowdoctrine-mapping.xsdtaken from doctrine/orm/doctrine-mapping.xsdUser.orm.xmltaken from friendsofsymfony/user-bundle/Resources/config/doctrine-mapping/User.orm.xmlindex.php:
Then:
$ php -S 127.0.0.1:8001Output:
Does this help? I assume it indicates a couple of errors in the XML-definition
@mleko64 commented on GitHub (Dec 13, 2023):
This is intresting: https://discourse.gnome.org/t/libxml2-2-12-0-released/18063
@yard-mschwartz commented on GitHub (Dec 13, 2023):
Yeah that's 99% it. My colleague who is on version 2.9.13 doesn't have these errors. In terms of solutions, I'm afraid they all go over my head.
The most reliable way forward for us is probably to rewrite our code so it doesn't use the FOS UserBundle anymore. Unfortunately, we will need to do this for multiple projects.
@greg0ire commented on GitHub (Dec 13, 2023):
💡 OK I think I get it
Invalid Schemais not an issue about the xml file, but about the xsd file itself, which explains whylibxml_use_internal_errors(true);does not remove the warning about the schema.@mleko64 commented on GitHub (Dec 13, 2023):
Exactly, the error concerns the schema file (doctrine-mapping.xsd), not the current xml file that needs to be checked.
@greg0ire commented on GitHub (Dec 13, 2023):
OK, well, let's take a look at the first error found by @yard-mschwartz I guess…
complex type 'sql-result-set-mapping': The content model is not determinist.It refers to this:
2b91edc525/doctrine-mapping.xsd (L146-L156)Let's try to get more info on that error, maybe from the PR that introduced it? There should be a commit labeled "regexp: Fix determinism checks" in libxml.
EDIT: here is the commit, couldn't find a PR for it:
a06eaa6119Related issue: https://gitlab.gnome.org/GNOME/libxml2/-/issues/624
I wonder if this could be caused by the
<xs:anytags in the schema… given their name, they sound like they could allow anything. If somebody with the error can try removing them and see if they still get the error aboutsql-result-set-mapping, that would help.@mbabker commented on GitHub (Dec 13, 2023):
Linked files as they are now:
After commenting the
<xs:anytag in thesql-result-set-mappingtype:So, yes, it does appear to be related to those tags and the issue reported by @shyim with Shopware's XSD at least looks somewhat related.
It's not all of the any's, either. This passes for
sql-result-set-mapping:@greg0ire commented on GitHub (Dec 13, 2023):
This is worrying: https://www.xml.com/axml/notes/Determinism.html
This is a bit more understandable: https://www.xml.com/axml/target.html#determinism
Translating the original
sql-result-set-mappinginto english, I think it says that when you have a tagsql-result-set-mapping, then you can must have anameattribute, and then inside you can have one of:entity-resultcolumn-resultIf you try commenting out the other
any, and not the first, does it also pass? If yes, this might mean that when you put something that isn'tentity-resultorcolumn-resultin there, it doesn't know whether it should validated that against the firstany, or the second one?@shyim commented on GitHub (Dec 13, 2023):
When you know exactly which elements will be inside the XML I would get rid of the
xsd:any. In our case it was allowed to add custom elements which were not described in the xsd.@greg0ire commented on GitHub (Dec 14, 2023):
Looking at the repository history, I can find this commit by myself:
12babcc1c2This is interesting as well: https://github.com/doctrine-extensions/DoctrineExtensions/issues/2613
@mbabker commented on GitHub (Dec 14, 2023):
Yeah, there's a whole chain of issues on the DoctrineExtensions repo about the XML mappings and validation issues in general, which to my understanding of https://github.com/doctrine-extensions/DoctrineExtensions/issues/2055 haven't even worked with the MongoDB ODM for years since they went strict on their schema and totally disallowed extending like the ORM had allowed.
@greg0ire commented on GitHub (Dec 15, 2023):
A way out of this would be to make the default schema stricter (remove all the
xs:any), so that it validates, and then allow defining custom schemas: https://github.com/doctrine/orm/issues/11123@AlbanDeveloppeur commented on GitHub (Dec 20, 2023):
Hello ! I've got the same issue, and I don't understand how to solve it. I've tried what I've seen here, but nothing changes. The problem appeared when I tried to upgrade my Project from Symfony 6.3 to 6.4. My libxml version is 2.9.1
@yard-mschwartz commented on GitHub (Dec 21, 2023):
Hi @AlbanDeveloppeur, from our current understanding the problem should only occur with libxml 2.12 onwards. Are you sure it's the same issue? Perhaps the error is the same, but the cause is different (e.g. you're not using
friendsofsymfony/user-bundle)@AlbanDeveloppeur commented on GitHub (Dec 22, 2023):
I work with
Symfony : 6.4.1
PHP : 8.2.10
doctrine/orm : 2.17.2
vich/uploader-bundle : 2.3.0
libxml : 2.9.1
Summary
Hello ! To update my issue from this comment : https://github.com/doctrine/orm/issues/11117#issuecomment-1864457851
In the development environnement I have this error message when I try to use
php bin/console cache:clearAnd when I'm in production environnement, I have this error message :
So for now, it seems to be the same problem you've discovered here.
After a lot of manipulations, I tried to delete some vendors. And after deleting
vich/uploader-bundle, both errors in the development and production environment have disappeared and I can dophp bin/console cache:clearagain.I don't know why this vendor created this type of issue, but in my case, deleting this vendor solved my problem.
@greg0ire commented on GitHub (Dec 22, 2023):
It does seem to be the same error. How did you determine the libxml version? I think looking at the output of
php -imight be the right way to do this in case it's possible to have several different versions on your system@aratinau commented on GitHub (Dec 26, 2023):
Hello
I have exactly the same problem, the only bundle I added is
symfonycasts/verify-email-bundle@danielsreichenbach commented on GitHub (Dec 28, 2023):
Using PHP 8.2.14 (compiled against libxml 2.12.0) with a Symfony 7 app.
This issue basically renders Symfony unusable. You can not use
make:entityor any other Doctrine workflow.Can confirm though that the removal of
xsd:anyfromdoctrine-mapping.xsdmakes things work again.@mbabker commented on GitHub (Dec 28, 2023):
Don't use 2.12.0 or 2.12.1, those versions had bugs causing PHP to segfault. https://github.com/php/php-src/issues/12847
@justpilot commented on GitHub (Dec 31, 2023):
As far as I know the version 2.12.3 should run fine, but it produces the same error.
@greg0ire commented on GitHub (Dec 31, 2023):
2.12.3 might not have the segmentation fault, but I see no reason why it would no longer have the schema validation error.
@danielsreichenbach commented on GitHub (Jan 7, 2024):
Can confirm
2.12.3still causes the schema validation error. Only remedy still remainsxsd:anychange.@japodhidev commented on GitHub (Jan 12, 2024):
Don't really know if this is a fix or just some cheat. I've had this problem which seems to be originating from
gesdinet/jwt-refresh-token-bundle. I came across https://github.com/doctrine-extensions/DoctrineExtensions/issues/2613 which suggested settingvalidate_xml_mapping: false. This seemed to fix my issue.Some probably useful info:
A little excerpt from my
composer.jsonI'm on Symfony version
6.4.2. Hope this sheds some light or possibly helps someone someway.@mbabker commented on GitHub (Jan 12, 2024):
It's a cheat. That
validate_xml_mappingsetting disables the XML schema validation, preventing the error in this thread from being triggered in the first place. And IIRC, that setting is no-op'd with ORM 3 and XML validation is always required.@IndraGunawan commented on GitHub (Jan 15, 2024):
still facing
DOMDocument::schemaValidate(): Invalid Schemaerror on libxml2 from HEAD commit@greg0ire commented on GitHub (Jan 15, 2024):
@IndraGunawan why do you expect it to be fixed?
@sophoniie commented on GitHub (Jan 15, 2024):
I have the same issue cause by :
vich/uploader-bundle@IndraGunawan commented on GitHub (Jan 15, 2024):
@greg0ire the issue was on libxml, is it? or xsd file needs some changes?
i downgraded libxml2 to 2.11.6 and compile the PHP 8.3.1. i don't see
invalid schemaerror@greg0ire commented on GitHub (Jan 15, 2024):
Why are you using the past tense? The issue still exists. Because of new libxml versions that are stricter since libxml 2.12, the XSD file is now considered invalid, and will need some changes, yes.
@sophoniie commented on GitHub (Jan 16, 2024):
@greg0ire so we need to update XSD file to make it valid, and the issue is solved ?
@greg0ire commented on GitHub (Jan 16, 2024):
Yes, but how we update it might cause issues to other users. For instance, @mbabker maintains a library that relies on adding extra elements to the mapping file (see https://github.com/doctrine-extensions/DoctrineExtensions/issues/2318). Right now, I think it works thanks to these
anyelements we need to remove.This is why a solution could be to allow custom schemas: https://github.com/doctrine/orm/issues/11123 . Users who would need to use extensions could specify a more complicated schema allowing for them. Such schemas could be maintained by libraries, so they would use e.g.
vendor/doctrine-extensions/DoctrineExtensions/extended-schema.xsd.@greg0ire commented on GitHub (Jan 16, 2024):
@mbabker could you maybe work on producing an XSD file that:
gedmo/doctrine-extensionsto work?@greg0ire commented on GitHub (Jan 16, 2024):
Note that it's possible to reproduce the issue without PHP, like this:
Applying the following patch appears to fix the issue:
@mbabker commented on GitHub (Jan 16, 2024):
Running
xmllintagainst this file with the below schema which imports the ORM 2.17.2 XSD and the doctrine-extensions 3.14.0 XSD:With this diff (based on the 2.17.2 tag), it validates:
@yard-mschwartz commented on GitHub (Jan 18, 2024):
Thanks @greg0ire for fixing this nasty problem.
If I'm not mistaken, the fix seems to be scheduled for 2.18.x. When can I expect 2.18.0 to be made available to the general public?EDIT My bad, it's already in 2.17.3. Thanks again!