{"action":"created","issue":{"url":"https://api.github.com/repos/doctrine/mongodb-odm/issues/563","labels_url":"https://api.github.com/repos/doctrine/mongodb-odm/issues/563/labels{/name}","comments_url":"https://api.github.com/repos/doctrine/mongodb-odm/issues/563/comments","events_url":"https://api.github.com/repos/doctrine/mongodb-odm/issues/563/events","html_url":"https://github.com/doctrine/mongodb-odm/issues/563","id":13409444,"number":563,"title":"If the database value of @DiscriminatorField changes to unsupported value, an Exception should be thrown instead of PHP Notice","user":{"login":"vmattila","id":435124,"avatar_url":"https://avatars.githubusercontent.com/u/435124?v=3","gravatar_id":"","url":"https://api.github.com/users/vmattila","html_url":"https://github.com/vmattila","followers_url":"https://api.github.com/users/vmattila/followers","following_url":"https://api.github.com/users/vmattila/following{/other_user}","gists_url":"https://api.github.com/users/vmattila/gists{/gist_id}","starred_url":"https://api.github.com/users/vmattila/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vmattila/subscriptions","organizations_url":"https://api.github.com/users/vmattila/orgs","repos_url":"https://api.github.com/users/vmattila/repos","events_url":"https://api.github.com/users/vmattila/events{/privacy}","received_events_url":"https://api.github.com/users/vmattila/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2013-04-19T16:51:08Z","updated_at":"2016-01-04T17:45:40Z","closed_at":null,"body":"Referring to the second issue in my SO question (http://stackoverflow.com/questions/15056946/doctrine-odm-returns-proxy-object-for-base-class-instead-of-sub-classed-document): if a database value of the discriminator field changes to some unsupported value, a PHP notice is thrown instead of proper exception.\r\n\r\nI tried to find a suitable place to test this and throw an exception so I could have submitted a PR with fix & test case, but unfortunately I do not know that much about mongodb-odm codebase to find a correct place for throwing an exception...\r\n\r\nHowever, I drafted a test case for the issue. Don't know whether HydratorException is the correct exception class and where this test function should be added (`Tests/Functional/InheritanceTest.php` maybe), but here is it anyway.\r\n\r\n```php\r\n/**\r\n * @expectedException \\Doctrine\\ODM\\MongoDB\\Hydrator\\HydratorException\r\n */\r\npublic function testUnsupportedDatabaseValueForDiscriminatorMapRaisesException()\r\n{\r\n\t$project = new \\Documents\\Project('Project');\r\n\t$this->dm->persist($project);\r\n\t$this->dm->flush();\r\n\r\n\t$id = $project->getId();\r\n\r\n\t$coll = $this->dm->getDocumentCollection('Documents\\Project');\r\n\t$document = $coll->findOne(array('name' => 'Project'));\r\n\t$this->assertEquals('project', $document['type']);\r\n\r\n\t// Changing database value for DiscriminatorMap field\r\n\t$coll->update(array('name' => 'Project'), array('$set' => array('type' => 'unsupported-type')));\r\n\t\r\n\t// Ensuring it's properly persisted\r\n\t$document = $coll->findOne(array('name' => 'Project'));\r\n\t$this->assertEquals('unsupported-type', $document['type']);\r\n\r\n\t// This query should raise \\Doctrine\\ODM\\MongoDB\\Mapping\\HydratorException\r\n\t// because 'unsupported-type' is not an allowed value in @DiscriminatorMap\r\n\t$document = $this->dm->find('Documents\\Project', $id);\r\n\t$this->assertInstanceOf('Documents\\Project', $document);\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/doctrine/mongodb-odm/issues/comments/168749161","html_url":"https://github.com/doctrine/mongodb-odm/issues/563#issuecomment-168749161","issue_url":"https://api.github.com/repos/doctrine/mongodb-odm/issues/563","id":168749161,"user":{"login":"malarzm","id":4947711,"avatar_url":"https://avatars.githubusercontent.com/u/4947711?v=3","gravatar_id":"","url":"https://api.github.com/users/malarzm","html_url":"https://github.com/malarzm","followers_url":"https://api.github.com/users/malarzm/followers","following_url":"https://api.github.com/users/malarzm/following{/other_user}","gists_url":"https://api.github.com/users/malarzm/gists{/gist_id}","starred_url":"https://api.github.com/users/malarzm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/malarzm/subscriptions","organizations_url":"https://api.github.com/users/malarzm/orgs","repos_url":"https://api.github.com/users/malarzm/repos","events_url":"https://api.github.com/users/malarzm/events{/privacy}","received_events_url":"https://api.github.com/users/malarzm/received_events","type":"User","site_admin":false},"created_at":"2016-01-04T17:45:40Z","updated_at":"2016-01-04T17:45:40Z","body":"Cross referencing with https://github.com/doctrine/mongodb-odm/issues/867"}}