Lensfun - Not finding the right lens

Have checked this a little bit more. The order darktable reads lens tags seem to be the culprit. Reading Exif.CanonCs.LensType before reading Exif.Photo.LensModel. It seems Canon Digital Photo 4 reads Exif.Photo.LensModel or Exif.Photo.LensModel first. Open a raw file in DPP4 and press CTRL+I. DPP4 will report EF35mm f/1.4L USM instead of Canon EF 35mm f/1.4L.

Some Canon lenses and cameras:

And the source code from darktable how to read the lens tags:

/* Read lens name /
if((FIND_EXIF_TAG(“Exif.CanonCs.LensType”)
&& pos->print(&exifData) != “(0)”
&& pos->print(&exifData) != “(65535)”)
|| FIND_EXIF_TAG(“Exif.Canon.0x0095”))
{
dt_strlcpy_to_utf8(img->exif_lens, sizeof(img->exif_lens), pos, exifData);
}
else if(Exiv2::testVersion(0,25,0) && FIND_EXIF_TAG(“Exif.PentaxDng.LensType”))
{
dt_strlcpy_to_utf8(img->exif_lens, sizeof(img->exif_lens), pos, exifData);
}
else if(FIND_EXIF_TAG(“Exif.Panasonic.LensType”))
{
dt_strlcpy_to_utf8(img->exif_lens, sizeof(img->exif_lens), pos, exifData);
}
else if(FIND_EXIF_TAG(“Exif.OlympusEq.LensType”))
{
/
For every Olympus camera Exif.OlympusEq.LensType is present. */
dt_strlcpy_to_utf8(img->exif_lens, sizeof(img->exif_lens), pos, exifData);

  /* We have to check if Exif.OlympusEq.LensType has been translated by
   * exiv2. If it hasn't, fall back to Exif.OlympusEq.LensModel. */
  std::string lens(img->exif_lens);
  if(std::string::npos == lens.find_first_not_of(" 1234567890"))
  {
    /* Exif.OlympusEq.LensType contains only digits and spaces.
     * This means that exiv2 couldn't convert it to human readable
     * form. */
    if(FIND_EXIF_TAG("Exif.OlympusEq.LensModel"))
    {
      dt_strlcpy_to_utf8(img->exif_lens, sizeof(img->exif_lens), pos, exifData);
    }
    /* Just in case Exif.OlympusEq.LensModel hasn't been found */
    else if(FIND_EXIF_TAG("**Exif.Photo.LensModel**"))
    {
      dt_strlcpy_to_utf8(img->exif_lens, sizeof(img->exif_lens), pos, exifData);
    }
    fprintf(stderr, "[exif] Warning: lens \"%s\" unknown as \"%s\"\n", img->exif_lens, lens.c_str());
  }
}
else if((pos = Exiv2::lensName(exifData)) != exifData.end() && pos->size())
{
  dt_strlcpy_to_utf8(img->exif_lens, sizeof(img->exif_lens), pos, exifData);
}

// finally the lens has only numbers and parentheses, let's try to use
// Exif.Photo.LensModel if defined.