Repository: conda/conda

Issue:
conda install error 'ValidationError: hard is not a valid LinkType'
This command:

    conda install numpy

causes this error:

```

An unexpected error has occurred.
Please consider posting the following information to the
conda GitHub issue tracker at:

    https://github.com/conda/conda/issues



Current conda install:

               platform : osx-64
          conda version : 4.3.6
       conda is private : False
      conda-env version : 4.3.6
    conda-build version : 1.21.5
         python version : 2.7.13.final.0
       requests version : 2.12.4
       root environment : /Users/mike/anaconda  (writable)
    default environment : /Users/mike/anaconda
       envs directories : /Users/mike/anaconda/envs
          package cache : /Users/mike/anaconda/pkgs
           channel URLs : https://conda.anaconda.org/hydrocomputing/osx-64
                          https://conda.anaconda.org/hydrocomputing/noarch
                          https://repo.continuum.io/pkgs/free/osx-64
                          https://repo.continuum.io/pkgs/free/noarch
                          https://repo.continuum.io/pkgs/r/osx-64
                          https://repo.continuum.io/pkgs/r/noarch
                          https://repo.continuum.io/pkgs/pro/osx-64
                          https://repo.continuum.io/pkgs/pro/noarch
                          https://conda.anaconda.org/conda-forge/osx-64
                          https://conda.anaconda.org/conda-forge/noarch
                          https://conda.anaconda.org/Esri/osx-64
                          https://conda.anaconda.org/Esri/noarch
            config file : /Users/mike/.condarc
           offline mode : False
             user-agent : conda/4.3.6 requests/2.12.4 CPython/2.7.13 Darwin/15.6.0 OSX/10.11.6
                UID:GID : 501:20



`$ /Users/mike/anaconda/bin/conda install numpy`




    Traceback (most recent call last):
      File "/Users/mike/anaconda/lib/python2.7/site-packages/conda/exceptions.py", line 617, in conda_exception_handler
        return_value = func(*args, **kwargs)
      File "/Users/mike/anaconda/lib/python2.7/site-packages/conda/cli/main.py", line 137, in _main
        exit_code = args.func(args, p)
      File "/Users/mike/anaconda/lib/python2.7/site-packages/conda/cli/main_install.py", line 80, in execute
        install(args, parser, 'install')
      File "/Users/mike/anaconda/lib/python2.7/site-packages/conda/cli/install.py", line 136, in install
        linked_dists = install_linked(prefix)
      File "/Users/mike/anaconda/lib/python2.7/site-packages/conda/core/linked_data.py", line 121, in linked
        return set(linked_data(prefix, ignore_channels=ignore_channels).keys())
      File "/Users/mike/anaconda/lib/python2.7/site-packages/conda/core/linked_data.py", line 113, in linked_data
        load_linked_data(prefix, dist_name, ignore_channels=ignore_channels)
      File "/Users/mike/anaconda/lib/python2.7/site-packages/conda/core/linked_data.py", line 66, in load_linked_data
        linked_data_[prefix][dist] = rec = IndexRecord(**rec)
      File "/Users/mike/anaconda/lib/python2.7/site-packages/conda/_vendor/auxlib/entity.py", line 702, in __call__
        instance = super(EntityType, cls).__call__(*args, **kwargs)
      File "/Users/mike/anaconda/lib/python2.7/site-packages/conda/_vendor/auxlib/entity.py", line 719, in __init__
        setattr(self, key, kwargs[key])
      File "/Users/mike/anaconda/lib/python2.7/site-packages/conda/_vendor/auxlib/entity.py", line 831, in __setattr__
        super(ImmutableEntity, self).__setattr__(attribute, value)
      File "/Users/mike/anaconda/lib/python2.7/site-packages/conda/_vendor/auxlib/entity.py", line 424, in __set__
        instance.__dict__[self.name] = self.validate(instance, self.box(instance, val))
      File "/Users/mike/anaconda/lib/python2.7/site-packages/conda/_vendor/auxlib/entity.py", line 658, in box
        return val if isinstance(val, self._type) else self._type(**val)
      File "/Users/mike/anaconda/lib/python2.7/site-packages/conda/_vendor/auxlib/entity.py", line 702, in __call__
        instance = super(EntityType, cls).__call__(*args, **kwargs)
      File "/Users/mike/anaconda/lib/python2.7/site-packages/conda/_vendor/auxlib/entity.py", line 719, in __init__
        setattr(self, key, kwargs[key])
      File "/Users/mike/anaconda/lib/python2.7/site-packages/conda/_vendor/auxlib/entity.py", line 424, in __set__
        instance.__dict__[self.name] = self.validate(instance, self.box(instance, val))
      File "/Users/mike/anaconda/lib/python2.7/site-packages/conda/models/index_record.py", line 15, in box
        return super(LinkTypeField, self).box(instance, val)
      File "/Users/mike/anaconda/lib/python2.7/site-packages/conda/_vendor/auxlib/entity.py", line 557, in box
        raise ValidationError(val, msg=e1)
    ValidationError: hard is not a valid LinkType
```

It worked for several years. I am using many environments for different Python version. One of the last updates must have broken it. I cannot tell exactly which one.  



Discussion:
This is my clunky fix in `Users/mike/anaconda/lib/python2.7/site-packages/conda/_vendor/auxlib/entity.py` starting at line 545, changing `hard` into `hardlink`:

    def box(self, instance, val):
        if val is None:
            # let the required/nullable logic handle validation for this case
            return None
        try:
            # try to box using val as an Enum name
            return val if isinstance(val, self._type) else self._type(val)
        except ValueError as e1:
            try:
                if val == 'hard':
                    val = 'hardlink'
                # try to box using val as an Enum value
                return self._type[val]
            except KeyError:
                raise ValidationError(val, msg=e1)
Can you run again with `-v -v -v` (and without your fix)? I'd like to figure out where the bad package is. 

Resolving patch:
diff --git a/conda/models/index_record.py b/conda/models/index_record.py
--- a/conda/models/index_record.py
+++ b/conda/models/index_record.py
@@ -12,6 +12,10 @@ class LinkTypeField(EnumField):
     def box(self, instance, val):
         if isinstance(val, string_types):
             val = val.replace('-', '').replace('_', '').lower()
+            if val == 'hard':
+                val = LinkType.hardlink
+            elif val == 'soft':
+                val = LinkType.softlink
         return super(LinkTypeField, self).box(instance, val)
 
 


Test patch: