mirror of
https://github.com/inventree/InvenTree.git
synced 2026-03-30 08:01:07 +00:00
[Bug] Import-records fix when importing from older InvenTree+Postgres version (#10862)
* Fixed issue where importing data from older versions of InvenTree+Postgres would fail * Update tasks.py Changed .startswith to exact matching for users.userprofile. Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update tasks.py Added validation checks to user primary key pairing dict. Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Reverted tasks.py, disabled signals in user model when importing data --------- Co-authored-by: Oliver <oliver.henry.walters@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -600,6 +600,10 @@ class UserProfile(InvenTree.models.MetadataMixin):
|
||||
@receiver(post_save, sender=User)
|
||||
def create_or_update_user_profile(sender, instance, created, **kwargs):
|
||||
"""Create or update user profile when user is saved."""
|
||||
# Disable profile creation if importing data from file
|
||||
if isImportingData():
|
||||
return
|
||||
|
||||
if created:
|
||||
UserProfile.objects.create(user=instance)
|
||||
instance.profile.save()
|
||||
@@ -629,6 +633,10 @@ def validate_primary_group_on_delete(sender, instance, **kwargs):
|
||||
@receiver(m2m_changed, sender=User.groups.through)
|
||||
def validate_primary_group_on_group_change(sender, instance, action, **kwargs):
|
||||
"""Validate primary_group on user profiles when a group is added or removed."""
|
||||
# Disable user profile validation if importing data from file
|
||||
if isImportingData():
|
||||
return
|
||||
|
||||
if action in ['post_add', 'post_remove']:
|
||||
profile = instance.profile
|
||||
if profile.primary_group and profile.primary_group not in instance.groups.all():
|
||||
|
||||
Reference in New Issue
Block a user