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

[BC Break] Translation stopped working after 1.2.0 -> 1.3.0 update on Doctrine 2.6 #281

Closed
kiler129 opened this issue Jan 14, 2016 · 7 comments
Closed

Comments

@kiler129
Copy link

@kiler129 kiler129 commented Jan 14, 2016

Hi!
I think I maybe found a bug in the newest 1.3.0 release. I'm using translatable from DoctrineBehaviors along with a2lix/translation-form-bundle & Sonata.
After upgrade I noticed all translations are missing. To pinpoint that issue I downgraded Doctrine from 2.6.1 to 2.6.0 - result was the same. Next I've tried downgrading DoctrineBehaviors to 1.2.0, and bingo - everything started working.
I wrote minimal code to test it:

$pageRepo = $this->getDoctrine()->getRepository('XyzBundle:Page');
$page = $pageRepo->find(1);
var_dump($page);

On 1.3.0 it returns nulls where on 1.2.0 proper vales are returned.

Here're my implementation details (simplified to single-field, no setters, no comments to save space):
Mappings

<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
    <entity name="FooCompany\XyzBundle\Entity\Page" table="pages">
        <id name="id" type="integer" column="id">
            <generator strategy="AUTO"/>
            <options>
                <option name="unsigned">true</option>
            </options>
        </id>
        <field name="userEditable" type="boolean" column="user_editable" nullable="false"/>
    </entity>
</doctrine-mapping>
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
    <entity name="FooCompany\XyzBundle\Entity\PageTranslation" table="page_translations">
        <field name="title" type="string" column="title" length="255" nullable="false"/>
    </entity>
</doctrine-mapping>

Page entity

<?php

namespace FooCompany\XyzBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Model as ORMBehaviors;

class Page
{
    use ORMBehaviors\Translatable\Translatable;

    private $id;
    private $userEditable = false;

    public function getId()
    {
        return $this->id;
    }

    public function getTitle()
    {
        return $this->translate($this->getCurrentLocale())->getTitle();
    }

    public function getUserEditable()
    {
        return $this->userEditable;
    }

    public function __debugInfo()
    {
       return [
            'id' => $this->id,
            'title' => $this->getTitle(),
            'userEditable' => $this->userEditable
        ];
    }
}

PageTranslation entity

<?php

namespace FooCompany\XyzBundle\Entity;

use Knp\DoctrineBehaviors\Model as ORMBehaviors;

class PageTranslation
{
    use ORMBehaviors\Translatable\Translation;

    private $title;

    public function getTitle()
    {
        return $this->title;
    }

That issue may be related to another problem I noticed after update. If I try to edit translated entity I'm getting No identifier/primary key specified for Entity "Foo\XyzBundle\Entity\PageTranslation". Every Entity must have an identifier/primary key..
Despite my efforts I was unable to replicate that issue with few simple lines of code.

@docteurklein

This comment has been minimized.

Copy link
Contributor

@docteurklein docteurklein commented Jan 14, 2016

could you manually define the identifier in the translation class?

@kiler129

This comment has been minimized.

Copy link
Author

@kiler129 kiler129 commented Jan 14, 2016

Unfortunately it doesn't solve the problem - of course exception on form will disappear, but entity continues to contain only nulls.
I tried two approaches - mapping id field from trait and completely different field defined in translation class.

        <id name="id" type="integer" column="id">
            <generator strategy="AUTO"/>
            <options>
                <option name="unsigned">true</option>
            </options>
        </id>
        <id name="trId" type="integer" column="id">
            <generator strategy="AUTO"/>
            <options>
                <option name="unsigned">true</option>
            </options>
        </id>
@docteurklein

This comment has been minimized.

Copy link
Contributor

@docteurklein docteurklein commented Jan 14, 2016

ok. sorry for the problem. I'm not sure which commit introduced this regression, but if you have time to look at the diff between 1.2 and 1.3, that would be awesome.

EDIT: i looked at 1.2.0...1.3.0diff-70fa0cb795057a4d16c686305571a662

and I'm not sure what could introduce this regression.
Another possibility would be that you didn't enable translatable in the bundle config?

@kiler129

This comment has been minimized.

Copy link
Author

@kiler129 kiler129 commented Jan 14, 2016

Yeah... adding

knp_doctrine_behaviors:
  translatable: true

solved the problem - it was stupid :)

Don't you think, according to sem-ver, all values should be true by default in 1.3? Especially considering default version specification ~1.1 which will break many installations after update.
It's a very good thing to not enable everything in general, but it should be consistent with 1.2.

I propose to switch defaults to true and place a note in readme describing that all unused modules should be disabled and in 2.0 release flip all of them to default false.
What do you think?

@docteurklein

This comment has been minimized.

Copy link
Contributor

@docteurklein docteurklein commented Jan 14, 2016

you're totally right! this new configuration brings us a lot of problems, and it definitely breaks existing setups.

I'm not sure how to handle this tho.
EDIT: your solution seems good to me, but it might change behavior.

Anyway let's try. Can you open a PR and discuss it?

@samjarrett

This comment has been minimized.

Copy link

@samjarrett samjarrett commented Jan 20, 2016

Wanted to add a note that using Timestampable and SoftDeletable also were broken with this change.

Adding the config as described above for those two behaviors 'fixed' the issue.

@JulienItard

This comment has been minimized.

Copy link

@JulienItard JulienItard commented Jan 22, 2016

Hello,

when i did doctrine:schema:update --force
i had the errror :

No identifier/primary key specified for Entity "AppBundle\Entity\AlertTranslation". Every Entity must have an identifier/primary key.

Your solution fix it ! Thx

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

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.