SonataClassificationBundle icon indicating copy to clipboard operation
SonataClassificationBundle copied to clipboard

Creating a category is impossible in the fresh installation with category table empty.

Open t-works opened this issue 3 years ago • 6 comments

Environment

Sonata packages

show

sonata-project/admin-bundle              4.12.0            4.12.0          The missing Symfony Admin Generator
sonata-project/block-bundle              4.13.0            4.13.0          Symfony SonataBlockBundle
sonata-project/cache                     2.2.0             2.2.0           Cache library
Package sonata-project/cache is abandoned, you should avoid using it. No replacement was suggested.
sonata-project/classification-bundle     4.0.4             4.0.4           Symfony SonataClassificationBundle
sonata-project/doctrine-extensions       1.17.0            1.17.0          Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 4.3.0             4.3.0           Integrate Doctrine ORM into the SonataAd...
sonata-project/exporter                  2.13.0            2.13.0          Lightweight Exporter library
sonata-project/form-extensions           1.17.0            1.17.0          Symfony form extensions
sonata-project/formatter-bundle          5.0.x-dev 5ecbc1c 5.x-dev 6bc6e6a Symfony SonataFormatterBundle
sonata-project/media-bundle              4.2.0             4.2.0           Symfony SonataMediaBundle
sonata-project/twig-extensions           1.10.0            1.10.0          Sonata twig extensions
sonata-project/user-bundle               5.1.0             5.1.0           Symfony SonataUserBundle

Symfony packages

show

symfony/asset                      v6.1.0  v6.1.0  Manages URL generation and versioning of web assets such as CSS ...
symfony/cache                      v6.1.1  v6.1.1  Provides an extended PSR-6, PSR-16 (and tags) implementation
symfony/cache-contracts            v3.1.0  v3.1.0  Generic abstractions related to caching
symfony/config                     v6.1.0  v6.1.0  Helps you find, load, combine, autofill and validate configurati...
symfony/console                    v6.1.1  v6.1.1  Eases the creation of beautiful and testable command line interf...
symfony/dependency-injection       v6.1.0  v6.1.0  Allows you to standardize and centralize the way objects are con...
symfony/deprecation-contracts      v3.1.0  v3.1.0  A generic function and convention to trigger deprecation notices
symfony/doctrine-bridge            v6.1.0  v6.1.0  Provides integration for Doctrine with various Symfony components
symfony/dotenv                     v6.1.0  v6.1.0  Registers environment variables from a .env file
symfony/error-handler              v6.1.0  v6.1.0  Provides tools to manage errors and ease debugging PHP code
symfony/event-dispatcher           v6.1.0  v6.1.0  Provides tools that allow your application components to communi...
symfony/event-dispatcher-contracts v3.1.0  v3.1.0  Generic abstractions related to dispatching event
symfony/expression-language        v6.1.0  v6.1.0  Provides an engine that can compile and evaluate expressions
symfony/filesystem                 v6.1.0  v6.1.0  Provides basic utilities for the filesystem
symfony/finder                     v6.1.0  v6.1.0  Finds files and directories via an intuitive fluent interface
symfony/flex                       v2.2.2  v2.2.2  Composer plugin for Symfony
symfony/form                       v6.1.1  v6.1.1  Allows to easily create, process and reuse HTML forms
symfony/framework-bundle           v6.1.1  v6.1.1  Provides a tight integration between Symfony components and the ...
symfony/http-client                v6.1.1  v6.1.1  Provides powerful methods to fetch HTTP resources synchronously ...
symfony/http-client-contracts      v3.1.0  v3.1.0  Generic abstractions related to HTTP clients
symfony/http-foundation            v6.1.1  v6.1.1  Defines an object-oriented layer for the HTTP specification
symfony/http-kernel                v6.1.1  v6.1.1  Provides a structured process for converting a Request into a Re...
symfony/mailer                     v6.1.1  v6.1.1  Helps sending emails
symfony/maker-bundle               v1.43.0 v1.43.0 Symfony Maker helps you create empty commands, controllers, form...
symfony/mime                       v6.1.1  v6.1.1  Allows manipulating MIME messages
symfony/options-resolver           v6.1.0  v6.1.0  Provides an improved replacement for the array_replace PHP function
symfony/password-hasher            v6.1.0  v6.1.0  Provides password hashing utilities
symfony/polyfill-intl-grapheme     v1.26.0 v1.26.0 Symfony polyfill for intl's grapheme_* functions
symfony/polyfill-intl-icu          v1.26.0 v1.26.0 Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-intl-idn          v1.26.0 v1.26.0 Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-intl-normalizer   v1.26.0 v1.26.0 Symfony polyfill for intl's Normalizer class and related functions
symfony/polyfill-mbstring          v1.26.0 v1.26.0 Symfony polyfill for the Mbstring extension
symfony/property-access            v6.1.0  v6.1.0  Provides functions to read and write from/to an object or array ...
symfony/property-info              v6.1.1  v6.1.1  Extracts information about PHP class' properties using metadata ...
symfony/proxy-manager-bridge       v6.1.0  v6.1.0  Provides integration for ProxyManager with various Symfony compo...
symfony/routing                    v6.1.1  v6.1.1  Maps an HTTP request to a set of configuration variables
symfony/runtime                    v6.1.1  v6.1.1  Enables decoupling PHP applications from global state
symfony/security-acl               v3.3.1  v3.3.1  Symfony Security Component - ACL (Access Control List)
symfony/security-bundle            v6.1.0  v6.1.0  Provides a tight integration of the Security component into the ...
symfony/security-core              v6.1.0  v6.1.0  Symfony Security Component - Core Library
symfony/security-csrf              v6.1.0  v6.1.0  Symfony Security Component - CSRF Library
symfony/security-http              v6.1.1  v6.1.1  Symfony Security Component - HTTP Integration
symfony/serializer                 v6.1.1  v6.1.1  Handles serializing and deserializing data structures, including...
symfony/service-contracts          v3.1.0  v3.1.0  Generic abstractions related to writing services
symfony/stopwatch                  v6.1.0  v6.1.0  Provides a way to profile code
symfony/string                     v6.1.0  v6.1.0  Provides an object-oriented API to strings and deals with bytes,...
symfony/translation                v6.1.0  v6.1.0  Provides tools to internationalize your application
symfony/translation-contracts      v3.1.0  v3.1.0  Generic abstractions related to translation
symfony/twig-bridge                v6.1.0  v6.1.0  Provides integration for Twig with various Symfony components
symfony/twig-bundle                v6.1.1  v6.1.1  Provides a tight integration of Twig into the Symfony full-stack...
symfony/validator                  v6.1.1  v6.1.1  Provides tools to validate values
symfony/var-dumper                 v6.1.0  v6.1.0  Provides mechanisms for walking through any arbitrary PHP variable
symfony/var-exporter               v6.1.1  v6.1.1  Allows exporting any serializable PHP data structure to plain PH...
symfony/web-link                   v6.1.0  v6.1.0  Manages links between resources
symfony/web-profiler-bundle        v6.1.1  v6.1.1  Provides a development tool that gives detailed information abou...
symfony/yaml                       v6.1.0  v6.1.0  Loads and dumps YAML files

PHP version

PHP 8.1.5 (cli) (built: Apr 12 2022 17:38:30) (NTS Visual C++ 2019 x64)

Subject

The parent field on create category form is required. When no parent category is selected notification: This value should not be null. appears. Seems related to this frament if ($this->hasSubject()) { if (null !== $this->getSubject()->getParent() || null === $this->getSubject()->getId()) { // root category cannot have a parent $form ->add('parent', CategorySelectorType::class, [ 'category' => $this->getSubject(), 'model_manager' => $this->getModelManager(), 'class' => $this->getClass(), 'required' => true, 'context' => $this->getSubject()->getContext(), ]); } }

$form ->add('parent', CategorySelectorType::class, [ is executed when the category table is empty - effectively making creation of any category impossible.

Minimal repository with the bug

Steps to reproduce

Install bundle with php8 attributes used in entities (not tested if it fails also when annotations are used). doctrine:schema:update --force Go to categories in admin, add a category. Dropdown Parent is marked required and has no values. Write name. Submit.

Expected results

Category is created

Actual results

It fails with message: This value should not be null.

t-works avatar Jun 17 '22 02:06 t-works

Do you have a previous working version or it is always like this?

Just to make sure if this is something we broke with 4.0 or it was already broken.

jordisala1991 avatar Jun 25 '22 12:06 jordisala1991

Nope I tried to install this the first time. This is related to context. Sorry travelling, I may have a chance to get back to this project later this week or Sunday at worst. I'll be able to be more specific then.

sob., 25 cze 2022, 14:35 użytkownik Jordi Sala Morales < @.***> napisał:

Do you have a previous working version or it is always like this?

Just to make sure if this is something we broke with 4.0 or it was already broken.

— Reply to this email directly, view it on GitHub https://github.com/sonata-project/SonataClassificationBundle/issues/847#issuecomment-1166274736, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJDRXYMA63CSZ7HESJ25SATVQ34K5ANCNFSM5ZA2JNFA . You are receiving this because you authored the thread.Message ID: @.*** com>

t-works avatar Jun 27 '22 15:06 t-works

HI @t-works, any news ?

I'm not sure to understand the check

if (null !== $this->getSubject()->getParent() || null === $this->getSubject()->getId())

@jordisala1991 Do you use this bundle ? (and know what are categories/root categories)

Seems like indeed that the null === $this->getSubject()->getId() check disallow the right to create root category.

VincentLanglet avatar Aug 02 '22 21:08 VincentLanglet

I dont use this bundle sorry, but it seems indeed a problem that needs to be solved.

jordisala1991 avatar Aug 02 '22 22:08 jordisala1991

We should be able to create a test that reproduces the issue (functional) and fix it. Will try, soon...

jordisala1991 avatar Aug 09 '22 16:08 jordisala1991

Hi, sorry I got 5 projects to handle at work and not much time to play with that (it's my pet project). I managed to get it going by hacking the module. I feel really bad I didn't have time to get back to you. I'll do my best to find some time this week to describe my solution.

wt., 2 sie 2022, 23:52 użytkownik Vincent Langlet @.***> napisał:

HI @t-works https://github.com/t-works, any news ?

I'm not sure to understand the check

if (null !== $this->getSubject()->getParent() || null === $this->getSubject()->getId())

@jordisala1991 https://github.com/jordisala1991 Do you use this bundle ? (and know what are categories/root categories)

Seems like indeed that the null === $this->getSubject()->getId() check disallow the right to create root category.

— Reply to this email directly, view it on GitHub https://github.com/sonata-project/SonataClassificationBundle/issues/847#issuecomment-1203249826, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJDRXYJTDMKYJ6W6VRXCFKTVXGKCRANCNFSM5ZA2JNFA . You are receiving this because you were mentioned.Message ID: @.*** com>

t-works avatar Oct 11 '22 08:10 t-works

There are some places in the code where we create root categories for a context it they do not exist.

IMO, if you are not suposed to create root categories, then they should be created somehow when you first access the create.

I guess we will need to add some test of the creation of the initial category to better see how to do it.

jordisala1991 avatar Apr 01 '23 16:04 jordisala1991