Magento2: events.xml cant have no childrens, others can [Magento 2.2.4]

Created on 7 Jun 2018  路  12Comments  路  Source: magento/magento2

Preconditions

  1. Using Magento 2.2.4
  2. PHP 7.0.30

Steps to reproduce

  1. Create new module
  2. Create di.xml, events.xml, crontab.xml additionally to needed module.xml
  3. Fill all files correctly with its nessecary headers but dont put any children in it
    Example for di.xml:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
</config>

  1. run php bin/magento setup:upgrade && php bin/magento cache:flush && php bin/magento cache:clean

Expected result

  1. Upgrade + Flush + Clean should run fine trough, page is loading afterwards in developer mode

Actual result

  1. Upgrade runs fine, Cache Flush triggers the error (cache:clean does not)
  2. Error Message:
  [Magento\Framework\Exception\LocalizedException]                               
  Invalid XML in file /var/www/html/app/code/Vendor/Modulename/etc/events.xml:  
  Element 'config': Missing child element(s). Expected is ( event ).             
  Line: 2        

This is not logically as it should render fine, process the file even with no config in it, as it process other files.

FrameworEvent Fixed in 2.2.x Fixed in 2.3.x Clear Description Confirmed Format is valid Ready for Work Reproduced on 2.2.x Reproduced on 2.3.x good first issue

All 12 comments

Hello @nopenopenope, thank you for your report.
We've acknowledged the issue and added to our backlog.

Looks like the only thing which should be changed is set minOccurs from "1" to "0":
https://github.com/magento/magento2/blob/075de969fc470463a58c412f8a4d6d497f9b79a6/lib/internal/Magento/Framework/Event/etc/events.xsd#L12
If you'd like, you can create pull request to fix this issue.

@engcom-backlog-nickolas are you sure you need to fix this by setting minOccurs from "1" to "0"? Should the developer just not create the events.xml file since no events are added?

The crontab.xsd also has the minOccurs set to "1" for the group element in the config part. Maybe the di.xml should have a more strict xsd to require at least one preference, type or virtualType.

I think your suggestion will make the code less strict and therefore not a step in the good direction.

Please advice to not add an empty events.xml when you do not need one.

@arnoudhgz

Whatever way they choose, it should be unified. Right now there can be empty XMLs, but no empty events.xml.

@arnoudhgz if you downvote something, one should have the courage to explain why its a bad idea. Please elaborate if possible.

@nopenopenope I don't think everything should work the same, a di.xml and a events.xml have a different purpose. It is nice that events.xml can't be added empty, that the xsd blocks this for you.

Don't add empty files if you need them. My opinion is that it should not be unified with 'whatever way they choose'. The can improve other xsds, but they should never downgrade the xsd for the events by making it less strict just to have in a unified way.

I ran into this problem myself sometimes, when putting some xml code in comments in the events.xml or crontab.xml file, just for testing something quickly. It's really annoying then to have to remove the entire file just because the xsd file blocks an empty file. I'd appreciate it if the file can exist but be empty.

I agree that having empty files in a module makes no sense, but for quickly debugging something it would still be nice if this would be allowed.

Also in that case, quickly testing something should not be more important than having strict code, which in the end is more error proof.
I don't see the hassle with removing (or renaming) a file shortly if you want the events disabled for testing something.

Hi @lisovyievhenii. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if your want to validate it one more time, please, go though the following instruction:

  • [ ] 1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.
  • [x] 2. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [x] 3. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • [ ] 4. If the issue is not relevant or is not reproducible any more, feel free to close it.

@arnoudhgz,

more important than having strict code, which in the end is more error proof

I don't see how allowing empty events.xml makes code less error proof.

Hi @nopenopenope. Thank you for your report.
The issue has been fixed in magento/magento2#19146 by @lisovyievhenii in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming 2.3.1 release.

Hi @nopenopenope. Thank you for your report.
The issue has been fixed in magento/magento2#19145 by @lisovyievhenii in 2.2-develop branch
Related commit(s):

The fix will be available with the upcoming 2.2.8 release.

I am facing this issue anyone knows: Invalid Document
Element 'route': Missing child element(s). Expected is ( resources ).
Line: 23

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jzalenski picture jzalenski  路  3Comments

denis-g picture denis-g  路  3Comments

xi-ao picture xi-ao  路  3Comments

BenSpace48 picture BenSpace48  路  3Comments

phirunson picture phirunson  路  3Comments