Skip to content

Commit

Permalink
0.2.17.6
Browse files Browse the repository at this point in the history
========

* **Fix:** Fixed a bug in ``ProjectMixin`` where a proper cascade was not
  defined and the Delete operations to the Project table were not cascaded
  to the in the mixed-in classes properly.
  • Loading branch information
eoyilmaz committed Jan 2, 2017
1 parent befc566 commit c69442c
Show file tree
Hide file tree
Showing 7 changed files with 225 additions and 202 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG
Expand Up @@ -2,6 +2,13 @@
Stalker Changes
===============

0.2.17.6
========

* **Fix:** Fixed a bug in ``ProjectMixin`` where a proper cascade was not
defined and the Delete operations to the Project table were not cascaded
to the in the mixed-in classes properly.

0.2.17.5
========

Expand Down
375 changes: 187 additions & 188 deletions docs/source/_static/images/stalker_design.vue

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion stalker/__init__.py
Expand Up @@ -23,7 +23,7 @@

import sys

__version__ = '0.2.17.5'
__version__ = '0.2.17.6'


__string_types__ = []
Expand Down
24 changes: 15 additions & 9 deletions stalker/models/mixins.py
Expand Up @@ -690,13 +690,18 @@ def computed_total_seconds(self):
class ProjectMixin(object):
"""Allows connecting a :class:`.Project` to the mixed in object.
This also forces a ``all, delete-orphan`` cascade, so when a
:class:``.Project`` instance is deleted then all the class instances that
are inherited from ``ProjectMixin`` will also be deleted. Meaning that, a
class which also derives from ``ProjectMixin`` will not be able to exists
without a project (``delete-orphan`` case).
:param project: A :class:`.Project` instance holding the project which this
object is related to. It can not be None, or anything other than a
:class:`.Project` instance.
:type project: :class:`.Project`
"""

# # add this lines for Sphinx
# __tablename__ = "ProjectMixins"

Expand All @@ -705,28 +710,29 @@ def project_id(cls):
return Column(
"project_id",
Integer,
#ForeignKey("Projects.id", use_alter=True, name="project_x_id"),
ForeignKey("Projects.id"),
# cannot use nullable cause a Project object needs
# insert itself as the project and it needs post_update
# thus nullable should be True
#nullable=False,
)

@declared_attr
def project(cls):
backref = cls.__tablename__.lower()
from sqlalchemy.orm import backref
backref_table_name = cls.__tablename__.lower()
doc = """The :class:`.Project` instance that
this object belongs to.
"""

return relationship(
"Project",
primaryjoin=
cls.__tablename__ + ".c.project_id==Projects.c.id",
primaryjoin="%s.c.project_id==Projects.c.id" % cls.__tablename__,
post_update=True, # for project itself
uselist=False,
backref=backref,
backref=backref(
backref_table_name,
cascade='all, delete-orphan'
),
doc=doc
)

Expand Down Expand Up @@ -786,7 +792,7 @@ def references(cls):
'Link',
cls.__tablename__,
'Links',
cls.__name__ + "_References"
"%s_References" % cls.__name__
)
# return the relationship
return relationship(
Expand Down Expand Up @@ -866,7 +872,7 @@ def __acl__(self):
"""
return [(perm.access,
'%s:%s' % (self.__class__.__name__, self.name),
perm.action + '_' + perm.class_name)
'%s_%s' % (perm.action, perm.class_name))
for perm in self.permissions]


Expand Down
6 changes: 3 additions & 3 deletions stalker/models/repository.py
Expand Up @@ -80,9 +80,9 @@ class Repository(Entity):
ForeignKey('Entities.id'),
primary_key=True,
)
linux_path = Column(String(256))
windows_path = Column(String(256))
osx_path = Column(String(256))
linux_path = Column(String(256)) # \
windows_path = Column(String(256)) # -> these should be all unique
osx_path = Column(String(256)) # /

def __init__(self,
linux_path="",
Expand Down
1 change: 1 addition & 0 deletions stalker/models/ticket.py
Expand Up @@ -152,6 +152,7 @@ class Ticket(Entity, StatusMixin):
"id", Integer, ForeignKey("Entities.id"), primary_key=True
)

# TODO: use ProjectMixin
project_id = Column('project_id', Integer, ForeignKey('Projects.id'),
nullable=False)

Expand Down
12 changes: 11 additions & 1 deletion tests/db/test_db.py
Expand Up @@ -3371,7 +3371,6 @@ def test_persistence_of_Project(self):
resources=[user3],
responsible=[user1]
)

dt = datetime.datetime
td = datetime.timedelta
new_project._computed_start = dt.now()
Expand All @@ -3388,6 +3387,14 @@ def test_persistence_of_Project(self):
db.DBSession.add(ticket1)
db.DBSession.commit()

# create dailies
from stalker import Daily
d1 = Daily(name='Daily1', project=new_project)
d2 = Daily(name='Daily2', project=new_project)
d3 = Daily(name='Daily3', project=new_project)
db.DBSession.add_all([d1, d2, d3])
db.DBSession.commit()

# store the attributes
assets = new_project.assets
code = new_project.code
Expand Down Expand Up @@ -3470,6 +3477,9 @@ def test_persistence_of_Project(self):
# Tickets
self.assertEqual([], Ticket.query.all())

# Dailies
self.assertEqual([], Daily.query.all())

def test_persistence_of_Repository(self):
"""testing the persistence of Repository
"""
Expand Down

0 comments on commit c69442c

Please sign in to comment.