Skip to content

Commit

Permalink
Don't try to coerce types to themselves.
Browse files Browse the repository at this point in the history
This fixes unpersistence of classes whose constructors cannot take an
object of the same type.

No regression test, because I can't figure out how the existing test
code assigns a formatter to ``MetricsExample``.
  • Loading branch information
kfindeisen committed Nov 26, 2019
1 parent 1ede414 commit 3ebe3e4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion python/lsst/daf/butler/formatters/jsonFormatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,9 @@ def _coerceType(self, inMemoryDataset, storageClass, pytype=None):
Object of expected type `pytype`.
"""
if not hasattr(builtins, pytype.__name__):
inMemoryDataset = storageClass.assembler().assemble(inMemoryDataset, pytype=pytype)
if storageClass.isComposite():
inMemoryDataset = storageClass.assembler().assemble(inMemoryDataset, pytype=pytype)
elif not isinstance(inMemoryDataset, pytype):
# Hope that we can pass the arguments in directly
inMemoryDataset = pytype(inMemoryDataset)
return inMemoryDataset
2 changes: 1 addition & 1 deletion python/lsst/daf/butler/formatters/yamlFormatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def _coerceType(self, inMemoryDataset, storageClass, pytype=None):
if not hasattr(builtins, pytype.__name__):
if storageClass.isComposite():
inMemoryDataset = storageClass.assembler().assemble(inMemoryDataset, pytype=pytype)
else:
elif not isinstance(inMemoryDataset, pytype):
# Hope that we can pass the arguments in directly
inMemoryDataset = pytype(inMemoryDataset)
return inMemoryDataset

0 comments on commit 3ebe3e4

Please sign in to comment.