orm: DOMDocument schemaValidate error migrating to PHP 8.2
BC Break Report
Q | A |
---|---|
BC Break | not sure |
Version | 2.17.1 (latest at time of writing) |
Summary
Currently upgrading one our projects to PHP 8.2 from PHP 7.4. Application runs fine on PHP 7.4 with doctrine/orm
already on 2.17.1. However, when I bump the PHP-version to ^8.2
and run composer upgrade
, the subsequent symfony console cache:clear
fails with an Warning: DOMDocument::schemaValidate(): Invalid Schema
error.
Previous behavior
The commands symfony console cache:clear
works just fine.
Current behavior
When I bump the PHP-version to ^8.2
and run composer upgrade
, the subsequent symfony console cache:clear
fails with the following error:
[WARNING] Some commands could not be registered:
In XmlDriver.php line 1006:
Warning: DOMDocument::schemaValidate(): Invalid Schema
Line 1006 is the schemaValidate()
in the following code block in [...]/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php
:
$backedUpErrorSetting = libxml_use_internal_errors(true);
try {
$document = new DOMDocument();
$document->load($file);
if (! $document->schemaValidate(__DIR__ . '/../../../../../doctrine-mapping.xsd')) {
throw MappingException::fromLibXmlErrors(libxml_get_errors());
}
// more code here
}
When I dump the $file
that’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. Both doctrine/orm
and friendsofsymfony/user-bundle
were 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:
[WARNING] Some commands could not be registered:
In XmlDriver.php line 1006:
Warning: DOMDocument::schemaValidate(): complex type 'sql-result-set-mapping': The content model is not determinist.
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-bundle
file 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?
About this issue
- Original URL
- State: closed
- Created 7 months ago
- Comments: 41 (19 by maintainers)
Running
xmllint
against 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:
2.12.3 might not have the segmentation fault, but I see no reason why it would no longer have the schema validation error.
Linked files as they are now:
After commenting the
<xs:any
tag in thesql-result-set-mapping
type: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
: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!
@mbabker could you maybe work on producing an XSD file that:
gedmo/doctrine-extensions
to work?It’s a cheat. That
validate_xml_mapping
setting 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.Can confirm
2.12.3
still causes the schema validation error. Only remedy still remainsxsd:any
change.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
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.
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.Exactly, the error concerns the schema file (doctrine-mapping.xsd), not the current xml file that needs to be checked.
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.