id summary reporter owner description type status component version severity resolution keywords cc stage has_patch needs_docs needs_tests needs_better_patch easy ui_ux 25547 refresh_from_db leaves FieldFile with reference to db_instance vinnyrose nobody "#### models.py {{{#!python class Product(models.Model): myfile = models.FileField(upload_to='folder') }}} ##### elsewhere.py {{{#!python product = Product.objects.create(myfile='filename') product.refresh_from_db() assert id(product.myfile.instance) == id(product) # false }}} {{{product.file.instance}}} is actually {{{db_instance}}} which is used internally in {{{refresh_from_db}}}. This leads to strange results when trying to use {{{FieldFile.save}}} or {{{FieldFile.delete}}}, since you would be modifying {{{db_instance}}} instead of the intended {{{instance}}}. This also means any field that uses a {{{descriptor_class}}} that returns an {{{attr_class}}} will have this same issue, I've used this pattern for custom fields. This could most simply be fixed in the {{{FileDescriptor}}} itself, because frankly I don't see how this could be fixed for all cases in which a field has reference to the {{{instance}}} from which it was instatianted from. Perhaps a warning on {{{refresh_from_db}}} in the docs about this risk? " Bug closed Database layer (models, ORM) 1.8 Normal fixed refresh_from_db, fieldfile Accepted 1 0 0 0 0 0