Skip to content

Commit 2b08a30

Browse files
Silvan-WMDEWMDE bot
authored andcommitted
Avoid self-referencing loop for new Properties
Bug: T374230 Change-Id: Id46af0cea4305b30648988987b71bf27678bc7d6
1 parent aac809d commit 2b08a30

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/Lookup/EntityRetrievingDataTypeLookup.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class EntityRetrievingDataTypeLookup implements PropertyDataTypeLookup {
2020
* @var EntityLookup
2121
*/
2222
private $entityLookup;
23+
private array $propertyIdsInProcess = [];
2324

2425
public function __construct( EntityLookup $entityLookup ) {
2526
$this->entityLookup = $entityLookup;
@@ -34,6 +35,11 @@ public function __construct( EntityLookup $entityLookup ) {
3435
* @throws PropertyDataTypeLookupException
3536
*/
3637
public function getDataTypeIdForProperty( PropertyId $propertyId ) {
38+
if ( array_key_exists( $propertyId->getSerialization(), $this->propertyIdsInProcess ) ) {
39+
// avoid self-referencing loop for newly created properties (T374230)
40+
throw new PropertyDataTypeLookupException( $propertyId, 'loop detected' );
41+
}
42+
$this->propertyIdsInProcess[ $propertyId->getSerialization() ] = true;
3743
return $this->getProperty( $propertyId )->getDataTypeId();
3844
}
3945

@@ -50,6 +56,8 @@ private function getProperty( PropertyId $propertyId ) {
5056
throw new PropertyDataTypeLookupException( $propertyId );
5157
}
5258

59+
unset( $this->propertyIdsInProcess[ $propertyId->getSerialization() ] );
60+
5361
return $property;
5462
}
5563

0 commit comments

Comments
 (0)