Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Unable to re-run script after creating a class that inherits from base #359

Open
cslotboom opened this issue Dec 3, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@cslotboom
Copy link

When inheriting from base, I am unable to run a script twice without getting a value error my custom class. Looks like some persistent global registry object isn't getting properly refreshed on each run?

I'm creating the object below, and I get this error when running twice:

class PointGroup(Base, speckle_type="UserObject"):
    
    def __init__(self, points:list[Node], lines:list[Element2D] = None):
        self.points = points
        self.lines = lines

image

System Info

WIndows 11,
specklepy = 2.21

@cslotboom cslotboom added the bug Something isn't working label Dec 3, 2024
Copy link

linear bot commented Dec 3, 2024

@gjedlicska
Copy link
Collaborator

Hey @cslotboom, it would be nice to understand where you are running this script. The execution environment is probably trying to re-parse your code in a running environment.

I can only reproduce this in a plain python script by registering the same class in 2 different places:

from specklepy.objects.base import Base
from specklepy.objects.structural.geometry import Element2D, Node


class PointGroup(Base, speckle_type="UserObject"):
     
    def __init__(self, points:list[Node], lines:list[Element2D] = None):
        self.points = points
        self.lines = lines



class PointGroup(Base, speckle_type="UserObject"):
     
    def __init__(self, points:list[Node], lines:list[Element2D] = None):
        self.points = points
        self.lines = lines

produces the same error

Traceback (most recent call last):
  File "/home/gergojedlicska/Speckle/specklepy/example/register.py", line 13, in <module>
    class PointGroup(Base, speckle_type="UserObject"):
  File "/home/gergojedlicska/Speckle/specklepy/src/specklepy/objects/base.py", line 174, in __init_subclass__
    raise ValueError(
ValueError: The speckle_type: UserObject is already registered for type: PointGroup. Please choose a different type name.

so most probably this is what is happening in your scripting environment. Ideally this situation would be avoided, by only running the class definition once on startup, cause we have no extensive check to make sure the two type definitions match 1-1.

If you override the type definition with some differences, things can get weird unexpectedly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants