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

Bug? "Attempted to load class "Unique" from namespace […]MongoDBBundle\Validator\Constraints" #1851

Closed
spackmat opened this issue Jun 3, 2015 · 44 comments

Comments

@spackmat
Copy link

spackmat commented Jun 3, 2015

Hi,

I get the following error message, when I use the User class with Doctrine:

Attempted to load class "Unique" from namespace "\Symfony\Component\Validator\Constraints\Doctrine\Bundle\MongoDBBundle\Validator\Constraints". Did you forget a "use" statement for another namespace?

See also https://stackoverflow.com/questions/30304551/fosuserbundle-use-mongodb-config-validation-instead-of-orm

As a dirty workaround, I copied the constraint class definitions from the /friendsofsymfony/user-bundle/FOS/UserBundle/Resources/config/validation/orm.xml to the mongodb.xml and the couchdb.xml.

Seems as they are both loaded but should not. Is this a bug or a misconfiguration of mine?

@stof
Copy link
Member

stof commented Jun 3, 2015

This issue has already been solved in 1.3.6 and in the dev version of 2.0. Just update your bundle.

@spackmat
Copy link
Author

spackmat commented Jun 3, 2015

Hey thanks, I schould have updated my composer.json :/

@spackmat spackmat closed this as completed Jun 3, 2015
@desarrolla2
Copy link

I have the same error, with the latest version of 2.0 3efbc08

@stof
Copy link
Member

stof commented Jun 15, 2015

@desarrolla2 are you getting this error in the prod env or in the dev env ? If it is in prod, make sure to clear your cache.

@desarrolla2
Copy link

I have the error in prod, and i cleaned cache, ( and removed complete directory to be sure )

@desarrolla2
Copy link

I just update to Symfony 2.7 from 2.6 maybe is related to this.

@stof I suggest to reopen this ticket

@desarrolla2
Copy link

I downgrade to 2.6 and work ok now. I have no time to investigate in order to give you more information.

@hrba
Copy link

hrba commented Jun 17, 2015

@desarrolla2 Most likely you're missing dependency to doctrine/mongodb-odm-bundle

@desarrolla2
Copy link

@hrba i dont have this dependency, but i didn't using odm otherwise docrine orm, so i think that should not have it.

is it correct?

@hrba
Copy link

hrba commented Jun 17, 2015

@desarrolla2 The problem is that right now validation xml is reffering to class which is in bundle you don't have included so it is dependency of FOSUserBundle. Not sure if this approach is right, but to get it working you have to pull those additional deps via composer. You can experience same issue with CouchDBBundle as well, so include doctrine/couchdb-odm-bundle.

@stof
Copy link
Member

stof commented Jun 17, 2015

validation.xml does not refer to these classes (at least not in FOSUserBundle, maybe in your own code but then it is your issue).
The only place we use the Unique constraint from MongoDBBundle is in a dedicated XML file which is loaded only when you configure FOSUserBundle to use the mongodb backend.

@hrba
Copy link

hrba commented Jun 17, 2015

I did not mentioned validation.xml but validation xmls, just had a typo.
So I use only mysql with FOSUserBundle and experienced errors about reference to:
Doctrine\Bundle\MongoDBBundle\Validator\Constraints\Unique in
vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Resources/config/validation/mongodb.xml
and
Doctrine\Bundle\CouchDBBundle\Validator\Constraints\UniqueEntity in
vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Resources/config/validation/couchdb.xml
which I obviously don't use explicitly.
So as a summary, this just happened after upgrade to symfony 2.7, no addiional configuration changes.

@stof
Copy link
Member

stof commented Jun 17, 2015

Can you open your app/cache/dev/appDevDebugProjectContainer.php file, locate the getValidator_BuilderService method in it and paste its code ?

@hrba
Copy link

hrba commented Jun 17, 2015

here you go:

protected function getValidator_BuilderService()
    {
        $this->services['validator.builder'] = $instance = \Symfony\Component\Validator\Validation::createValidatorBuilder();
        $instance->setConstraintValidatorFactory(new \Symfony\Bundle\FrameworkBundle\Validator\ConstraintValidatorFactory($this, array('validator.expression' => 'validator.expression', 'Symfony\\Component\\Validator\\Constraints\\EmailValidator' => 'validator.email', 'security.validator.user_password' => 'security.validator.user_password', 'doctrine.orm.validator.unique' => 'doctrine.orm.validator.unique')));
        $instance->setTranslator($this->get('translator.default'));
        $instance->setTranslationDomain('validators');
        $instance->addXmlMappings(array(0 => ($this->targetDirs[3].'/vendor/symfony/symfony/src/Symfony/Component/Form/Resources/config/validation.xml'), 1 => ($this->targetDirs[3].'/vendor/friendsofsymfony/oauth-server-bundle/FOS/OAuthServerBundle/Resources/config/validation.xml'), 2 => ($this->targetDirs[3].'/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Resources/config/validation.xml'), 3 => ($this->targetDirs[3].'/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Resources/config/validation/mongodb.xml'), 4 => ($this->targetDirs[3].'/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Resources/config/validation/orm.xml'), 5 => ($this->targetDirs[3].'/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Resources/config/validation/propel.xml'), 6 => ($this->targetDirs[3].'/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Resources/config/validation/couchdb.xml')));
        $instance->addYamlMappings(array(0 => ($this->targetDirs[3].'/vendor/aboutcoders/file-distribution-bundle/Resources/config/validation.yml')));
        $instance->enableAnnotationMapping($this->get('annotation_reader'));
        $instance->addMethodMapping('loadValidatorMetadata');
        $instance->addObjectInitializers(array(0 => $this->get('doctrine.orm.validator_initializer'), 1 => new \FOS\UserBundle\Validator\Initializer($this->get('fos_user.user_manager'))));
        $instance->addXmlMapping(($this->targetDirs[3].'/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/DependencyInjection/Compiler/../../Resources/config/validation/orm.xml'));
        return $instance;
    }

@stof
Copy link
Member

stof commented Jun 17, 2015

There is something really weird. It is adding Resources/config/validation/*.xml but these files don't exist anymore in FOSUserBundle.

@xabbuh
Copy link
Member

xabbuh commented Jun 17, 2015

@hrba Which FOSUserBundle version do you use?

@hrba
Copy link

hrba commented Jun 17, 2015

@xabbuh Latest master.

@stof
Copy link
Member

stof commented Jun 18, 2015

@hrba do you have any files in vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Resources/config/validation/ ? If yes, it means that your FOSUserBundle install is corrupted (having old files where it should not have them anymore). In such case, I suggest you to delete the vendor/friendsofsymfony/user-bundle folder and run composer install again

@hrba
Copy link

hrba commented Jun 18, 2015

@stof yes, I have the files in vendor. I'll remove it and see if that works.

@vamsiikrishna
Copy link

Removing files from the vendor is not solving the issue.
I deleted the vendor file of this bundle , installed 2.0.0-alpha1 version. Still having same issue. Also having this only after upgrading to Symfony 2.7

@stof
Copy link
Member

stof commented Jun 30, 2015

Well, 2.0.-alpha is before the bug fix. but you are the first one saying you are using the alpha1 release

@jamhall
Copy link

jamhall commented Jul 22, 2015

I too have this problem. Running Symfony 2.7.1 and FOS User bundle v2.0.0-alpha1

@stof
Copy link
Member

stof commented Jul 22, 2015

@jamhall 2.0-alpha1 is before the bugfix

@jamhall
Copy link

jamhall commented Jul 22, 2015

So has the bug been fixed on dev-master? (if so, could you give me a link to the commit, thanks!)

@stof
Copy link
Member

stof commented Jul 22, 2015

yes. See previous comments

@jamhall
Copy link

jamhall commented Jul 22, 2015

Thanks. I see the fix was done here: adam187@971658d

Could you release a new alpha version with the 2.7 fixes please if possible? I'd rather not use the master branch. Thank you!

@pix-art
Copy link

pix-art commented Jul 23, 2015

When will a new release be made for 2.0, including this bug fix? Because I don't want to lower my minimum-stability.

@vamsiikrishna
Copy link

when we overrode some parts of the bundle , we copied the /Resources directly into our bundle and made changes there.

even these files were copied:
/Resources/config/validation/couchdb.xml
/Resources/config/validation/mongodb.xml

After deleting the above files ( from our bundle ), the issue is solved .

Thanks

@dodev34
Copy link

dodev34 commented Aug 8, 2015

It's work for me, my composer :

    "php": ">=5.3.9",
    "symfony/symfony": "2.7.*",
    "doctrine/orm": "~2.2,>=2.2.3,<2.5",
    "doctrine/dbal": "<2.5",
    "doctrine/doctrine-bundle": "~1.4",
    "symfony/assetic-bundle": "~2.3",
    "symfony/swiftmailer-bundle": "~2.3",
    "symfony/monolog-bundle": "~2.4",
    "sensio/distribution-bundle": "~4.0",
    "sensio/framework-extra-bundle": "~3.0,>=3.0.2",
    "incenteev/composer-parameter-handler": "~2.0",

    "friendsofsymfony/user-bundle": "~1.3",
    "sonata-project/core-bundle": "~2.2",
    "sonata-project/admin-bundle": "~2.2",
    "sonata-project/user-bundle": "~2.2",
    "sonata-project/doctrine-orm-admin-bundle": "~2.1",
    "sonata-project/easy-extends-bundle": "2.1.7"

@platowski
Copy link

Still getting same error. I've switched to 'dev-master' and it works with Sf 2.7 on dev enviroments, but it triggers the same error on prod enviroment. All vendors cleaned etc, so it won't be corrupted install. Any suggestions?

@M4E
Copy link

M4E commented Sep 1, 2015

I have the same problem after the update ...

@stof
Copy link
Member

stof commented Sep 2, 2015

@M4E whihc version of the bundle are you using ?

@M4E
Copy link

M4E commented Sep 2, 2015

Thank, my composer, i'm using Doctrine but same problem :

        "php": ">=5.3.3",
        "symfony/symfony": "2.6.*",
        "doctrine/orm": "2.4.4",
        "doctrine/doctrine-bundle": "1.3.*@dev",
        "twig/extensions": "~1.0",
        "symfony/assetic-bundle": "~2.3",
        "symfony/swiftmailer-bundle": "~2.3",
        "symfony/monolog-bundle": "~2.4",
        "sensio/distribution-bundle": "~3.0",
        "sensio/framework-extra-bundle": "~3.0",
        "incenteev/composer-parameter-handler": "~2.0",
        "friendsofsymfony/user-bundle": "~2.0@dev",
        "hwi/oauth-bundle": "0.4.*@dev",
        "stof/doctrine-extensions-bundle": "dev-master",
        "jms/serializer-bundle" : "0.13.0",
        "jms/i18n-routing-bundle": "dev-master",
        "jms/translation-bundle": "dev-master",
        "gedmo/doctrine-extensions":"2.3.6",
        "a2lix/translation-form-bundle": "1.*@dev",
        "doctrine/doctrine-fixtures-bundle": "2.2.*",
        "sonata-project/admin-bundle": "~2.3",
        "sonata-project/doctrine-orm-admin-bundle": "~2.2",
        "jms/di-extra-bundle": "dev-master",
        "jms/payment-core-bundle": "1.0.*@dev",
        "sonata-project/media-bundle": "~2.3",
        "knplabs/knp-paginator-bundle": "~2.4",
        "pixassociates/sortable-behavior-bundle": "0.1",
        "ensepar/html2pdf-bundle" : "dev-master"

@stof
Copy link
Member

stof commented Sep 2, 2015

this does not tell me which version is installed. You should use composer show -i to get the list of the installed versions (you have the same info in the composer.lock file, but it is a lot less readable because it has lots of other data in it)

@M4E
Copy link

M4E commented Sep 2, 2015

Sorry.

336d9cd8ba0c5a462b3e70be144a7bef5377b219

@stof
Copy link
Member

stof commented Sep 2, 2015

@M4E same question than in #1851 (comment)

@M4E
Copy link

M4E commented Sep 2, 2015

Sorry @stof but all vendors cleaned etc, so it won't be corrupted install....

@M4E
Copy link

M4E commented Sep 2, 2015

@stof I identify the problem. All goes well if I do not use ApcClassLoader in my app.php, shame . May be the same for you @platowski . Sorry for my english

@platowski
Copy link

Damn, I switched to apcu and I wrote my own simillar ApcuClassLoader. - and problem exists

@samuelvi
Copy link

samuelvi commented Jun 22, 2016

In my case I solved the issue by just removing whole vendor folder and running composer update again.

The issue happened when I migrated from symfony 2.6.8 to symfony 2.8.

It's important NOT to keep old files in vendor folder from a previous symfony 2.8 version.

For those who use rsync to update from pre to prod, I recommend using --delete option for vendor folder (test if before using -n option for a dry-run test sync)

@koami
Copy link

koami commented Sep 22, 2017

Hi,
I tried all your methods but still got the same error. The strange thing is that in my local wamp server it's working just fine. But, in the online server it's a mess. @samuelvi , I made the same upgrade as you but deleting the FOS_USER reposiroty didn't help. I'm using this version of FOS "dev-master 315f837" and Symfony "v2.8.27".
The same error occur when I try to edit a profil or change the password.

@miladsafaei
Copy link

miladsafaei commented Apr 16, 2018

Hi,

For those who may get this error yet:

Check your own user bundle which you made for rewrite and customize fosUserBundle.

Too much time and lots of searches and no way to resolve, before checking my own user bundle!

Just remove this folder which is not needed in new versions of fos:

/Resources/config/validation

Good luck.

@brzuchal
Copy link

Had the same issue but composer req validator did the thing!

@koami
Copy link

koami commented Apr 19, 2018

I don't have a Validation folder in my config. Just the routing folder I add in.

fos

For the composer req validator I got this message.
[InvalidArgumentException]
Could not find package validator at any version for your minimum-stability (stable). Check the package spelling or
your minimum-stability

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

No branches or pull requests