FriendsOfSymfony / FOSUserBundle

Provides user management for your Symfony project. Compatible with Doctrine ORM & ODM, and custom storages.

Home Page:https://symfony.com/doc/master/bundles/FOSUserBundle/index.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Possible Problems With Symfony 4.3

richard4339 opened this issue · comments

Symfony FOSUserBundle versions: v2.1.0

Description of the problem including expected versus actual behavior: When attempting to reference the user entity that extends the model, you get validation errors in the upcoming Symfony 4.3 from the validator. It complains about not having the field superAdmin, (and if you add a fake superAdmin field) it then won't get past the group methods. I haven't experienced these issues with 4.2, and didn't experience them in 4.3 before attempting to actually reference and use the user entity. I assume this is related to the new Doctrine validation that is being introduced in Symfony 4.3, but I'm not sure how to disable this functionality for the class as they said that is "coming soon". Has anyone else noticed this issue, or am I missing something simple?

Steps to reproduce:

  1. Install the FOSUserBundle on a beta build of Symfony 4.3
  2. Attempt to call the user entity via Twig such that the new Doctrine validator kicks in

Provide logs (if relevant):
Property "superAdmin" does not exist in class "App\Entity\User"

Update: I forked to attempt to see if I could get around the problem, and I was able to by renaming some key methods (I'm not submitting this as a pull request because that clearly isn't an acceptable long-term solution). Renaming isSuperAdmin() and setSuperAdmin to userIsSuperAdmin() and userSetSuperAdmin(), and hasGroup() to userHasGroup() does at least get rid of the errors.

Why don't you use 2.1.0 instead of 2.1.2 (latest bugfix release)? Maybe not relevant, but I don't think v2.1.0 is supported. Try to run composer update (assuming you're requiring ^2.1) to update.

Attempt to call the user entity via Twig such that the new Doctrine validator kicks in

I don't understand what you mean. What has the Doctrine validator to do with Twig? I can't reproduce it with Symfony 4.3-beta2 and FOSUserBundle v2.1.0.

@richard4339 stay confident. It is the new Symfony Validator. I get the same error with a different bundle when my Entity class extends another abstract class. Searching for a fix...

@richard4339 stay confident. It is the new Symfony Validator. I get the same error with a different bundle when my Entity class extends another abstract class. Searching for a fix...

I'm going around in circles on it. I tried adding other virtual get methods, isFake() and hasFake() to both an unrelated entity and to my user entity that extends the model and had no problems. It's literally just the methods isSuperAdmin(), setSuperAdmin(), and hasGroup() causing the problem.

If you need a temporary workaround, feel free to grab the changes from my fork, it's just renaming the three functions above and changing the references to them in three other files, but there is clearly a larger problem here, be it with this bundle, the validator changes, or maybe something else.

@richard4339 I found this Symfony issue. It might be a bug. Let's see how it progresses. In meanwhile we keep searching to see and understand what exactly changed with the update to Symfony 4.3.0

@avramcosmin I tried on Symfony 4.3.1 and the problem still persists even thought the issue is closed and on the liberation notes.

I tried with Symfony 4.3.1 and also tried with FOS version 2.1.0. Still having the same problem.
After that I have to use lower version of Symfony 4.2 and it works fine with FOS.

Me to i have the same problem!

I try to update 'symfony/doctrine-bridge' but the problem still actual. (>4.2.9 and 4.3)
Symfony Exception - Property "superAdmin" does not exist in class "App\Entity\User"

Same problem

Update:
Solved with adding variables to src/Entity/User.php

private $superAdmin;
private $group;

I'm having the exact same problem

Symfony 4.3.1
friendsofsymfony/user-bundle 2.1.2 || 2.1.0

I have found a solution commenting in this file: config/packages/validator.yaml the following:

diff --git a/config/packages/validator.yaml b/config/packages/validator.yaml
index 1affc68..3fcd3f8 100644
--- a/config/packages/validator.yaml
+++ b/config/packages/validator.yaml
@@ -2,7 +2,3 @@ framework:
     validation:
         email_validation_mode: html5
 
-        # Enables validator auto-mapping support.
-        # For instance, basic validation constraints will be inferred from Doctrine's metadata.
-        auto_mapping:
-            App\Entity\: []

I'm sure I'm missing some new good stuff, but for now is working!
Still waiting for a better approach...

Have the same problem. Commented next lines and it works for me:

framework:
    validation:
#        auto_mapping:
#            App\Entity\: []

Have the same problem. Commented next lines and it works for me:

framework:
    validation:
#        auto_mapping:
#            App\Entity\: []

Works for me, but this disable entity validation for all entities

Hi,
I'm still facing the same issue. I've followed @sharipovmarat's suggestion, but when sending form data during user registration, "data.password", "data.superAdmin" and "data.groups" appear to be null.

Any suggestions about how to solve it?

@versions:

  • Symfony 4.3.0
  • friendsofsymfony/user-bundle v2.1.2

Regards,
Ginés.

@GinesGarcia i think you should use "constraints" instead of "mapping" annotation for your validation... idk.

Any progress on this issue? We're waiting to upgrade, but am holding back until this is resolved.

Enabling auto-mapping for the classes of the bundle is not something we support. We already define our validation mapping explicitly. If you want to use the auto-mapping feature of the symfony validator, take care of configuring it without applying on the FOSUserBundle user class.