Closed aryan68125 closed 3 weeks ago
I added created_by_id field in the database table using DB viewer but now I am getting this error no such column: pms_employeeobjective.is_active The relevant screen shot is provided here:
I did find is_active field in horilla model
class HorillaModel(models.Model):
created_at = models.DateTimeField(
auto_now_add=True,
null=True,
blank=True,
verbose_name=_("Created At"),
)
created_by = models.ForeignKey(
User,
on_delete=models.SET_NULL,
null=True,
blank=True,
editable=False,
verbose_name=_("Created By"),
)
is_active = models.BooleanField(default=True, verbose_name=_("Is Active"))
class Meta:
abstract = True
EmployeeObjective model is inheriting from HorillaModel. But for some reason It is still not creating is_active column in the table. The moment I added is_active column in the Table It started working This is not the right way to do it. please tell me why is_active column is not added when I run migrations. (please explain)
Hi @aryan68125 , Sorry for the inconvenience caused. Are you using the test database or your live database?
With Regards, Team Horilla
I am using test database that comes with your project sqlite db . Your project caught my eye and i promptly decided to test your project to see how it works and may be contribute in your project. It will be really helpful to me if you can explain what is going on with created_by_id column and created by field in horilla model which seems to be inherited by some models in your project like EmployeeObjective model in pms application for example, I also found another error regarding datetime parsing in your pms app views.py file ... I am currently looking at this issue and so far i found the problem is in 572 line in your pangination function. I will have to look deeper and then I will contact you just giving you a heads up ... I would really appreciate if you could look into this as well
So far This is what I've found:
def objective_filter_pagination(request, objective_own, objective_all):
"""
This view takes two arguments, all_objective,own_objecitve and returns some objects.
Args:
all_objective (queryset) : Queryset of objectives
own_objective (queryset) : Queryset of objectives
Returns:
All the filtered and paginated object will return.
"""
previous_data = request.GET.urlencode()
initial_data = {"archive": False} # set initial value of archive filter to False
field = request.GET.get("field")
if request.GET.get("status") != "Closed":
objective_own = objective_own
objective_all = objective_all
objective_filter_own = ObjectiveFilter(
request.GET or initial_data, queryset=objective_own
)
objective_filer_form = objective_filter_own.form
objective_filter_own = objective_filter_own.qs.order_by("-id")
objective_filter_all = ObjectiveFilter(
request.GET or initial_data, queryset=objective_all
).qs
user = request.user
employee = Employee.objects.filter(employee_user_id=user).first()
manager = False
if Objective.objects.filter(managers=employee).exists():
manager = True
objectives = Objective.objects.filter(managers=employee).distinct()
if request.user.has_perm("pms.view_objective"):
objectives = Objective.objects.all()
objectives = ActualObjectiveFilter(request.GET, queryset=objectives).qs
objectives = Paginator(objectives, get_pagination())
# objective_paginator_own = Paginator(objective_filter_own, get_pagination())
# objective_paginator_all = Paginator(objective_filter_all, get_pagination()) # -->this is where the error is occuring
#debugging code starts
print("Type of objective_filter_all:", type(objective_filter_all))
print("Value of get_pagination():", get_pagination())
# output --> objective_paginator_all is a queryset
# Type of objective_filter_all: <class 'django.db.models.query.QuerySet'>
# objective_paginator_all = Paginator(objective_filter_all, get_pagination())
for obj in objective_filter_all:
print(f"objective_filter_all {obj}")
# print("Type of created_at:", type(obj.created_at))
#debugging code ends
own_page = request.GET.get("page")
all_page = request.GET.get("all_page")
objectives_own = objective_paginator_own.get_page(own_page)
objectives_all = objective_paginator_all.get_page(all_page)
objectives = objectives.get_page(all_page)
now = datetime.datetime.now()
data_dict = parse_qs(previous_data)
get_key_instances(EmployeeObjective, data_dict)
context = {
"manager": manager,
"superuser": "true",
"objectives": objectives,
"own_objectives": objectives_own,
"all_objectives": objectives_all,
"objective_filer_form": ActualObjectiveFilter().form,
"pg": previous_data,
"current_date": now,
"filter_dict": data_dict,
"gp_fields": ObjectiveReGroup.fields,
"field": field,
}
return context
In this above function is where the problem is specifically in this line
objective_paginator_all = Paginator(objective_filter_all, get_pagination()) # -->this is where the error is occuring
I checked wheather objective_filter_all
is a query set or not , and yes indeed objective_filter_all happens to be a query set because It was returning Type of objective_filter_all: <class 'django.db.models.query.QuerySet'>
so that means something fishy is going on in this get_pagination() method
I did manage to locate this method in methods.py file inside base application
here is the method
def get_pagination():
from base.thread_local_middleware import _thread_locals
request = getattr(_thread_locals, "request", None)
user = request.user
page = DynamicPagination.objects.filter(user_id=user).first()
count = 50
if page:
count = page.pagination
return count
The method seems to be just fine to me , I wonder where the problem is , I think I am missing something , I wonder what?. I also checked the tables just to be sure if there are any inconsistencies in DB through Db viewer but I din't find any I will continue to do my research on this but it would be nice if you could arrange someone who is working on this project so that I can get a better understanding of this project. Thank you! @horilla-opensource
Relevant error screenshotis provided here: NOTE: The error I am getting is similar but if you look into the nitty gritty details then there may be differences because I made some changes into your code and then took the screen shot . But the underlying problem remains the same i.e date or datetime parsing error
I am using test database that comes with your project sqlite db . Your project caught my eye and i promptly decided to test your project to see how it works and may be contribute in your project. It will be really helpful to me if you can explain what is going on with created_by_id column and created by field in horilla model which seems to be inherited by some models in your project like EmployeeObjective model in pms application for example, I also found another error regarding datetime parsing in your pms app views.py file ... I am currently looking at this issue and so far i found the problem is in 572 line in your pangination function. I will have to look deeper and then I will contact you just giving you a heads up ... I would really appreciate if you could look into this as well
Hi @aryan68125 , Thanks for testing out Horilla and raising the issues. We'll look into the issue and get back to you asap with the solution for the same.
With Regards, Team Horilla
So far This is what I've found:
def objective_filter_pagination(request, objective_own, objective_all): """ This view takes two arguments, all_objective,own_objecitve and returns some objects. Args: all_objective (queryset) : Queryset of objectives own_objective (queryset) : Queryset of objectives Returns: All the filtered and paginated object will return. """ previous_data = request.GET.urlencode() initial_data = {"archive": False} # set initial value of archive filter to False field = request.GET.get("field") if request.GET.get("status") != "Closed": objective_own = objective_own objective_all = objective_all objective_filter_own = ObjectiveFilter( request.GET or initial_data, queryset=objective_own ) objective_filer_form = objective_filter_own.form objective_filter_own = objective_filter_own.qs.order_by("-id") objective_filter_all = ObjectiveFilter( request.GET or initial_data, queryset=objective_all ).qs user = request.user employee = Employee.objects.filter(employee_user_id=user).first() manager = False if Objective.objects.filter(managers=employee).exists(): manager = True objectives = Objective.objects.filter(managers=employee).distinct() if request.user.has_perm("pms.view_objective"): objectives = Objective.objects.all() objectives = ActualObjectiveFilter(request.GET, queryset=objectives).qs objectives = Paginator(objectives, get_pagination()) # objective_paginator_own = Paginator(objective_filter_own, get_pagination()) # objective_paginator_all = Paginator(objective_filter_all, get_pagination()) # -->this is where the error is occuring #debugging code starts print("Type of objective_filter_all:", type(objective_filter_all)) print("Value of get_pagination():", get_pagination()) # output --> objective_paginator_all is a queryset # Type of objective_filter_all: <class 'django.db.models.query.QuerySet'> # objective_paginator_all = Paginator(objective_filter_all, get_pagination()) for obj in objective_filter_all: print(f"objective_filter_all {obj}") # print("Type of created_at:", type(obj.created_at)) #debugging code ends own_page = request.GET.get("page") all_page = request.GET.get("all_page") objectives_own = objective_paginator_own.get_page(own_page) objectives_all = objective_paginator_all.get_page(all_page) objectives = objectives.get_page(all_page) now = datetime.datetime.now() data_dict = parse_qs(previous_data) get_key_instances(EmployeeObjective, data_dict) context = { "manager": manager, "superuser": "true", "objectives": objectives, "own_objectives": objectives_own, "all_objectives": objectives_all, "objective_filer_form": ActualObjectiveFilter().form, "pg": previous_data, "current_date": now, "filter_dict": data_dict, "gp_fields": ObjectiveReGroup.fields, "field": field, } return context
In this above function is where the problem is specifically in this line
objective_paginator_all = Paginator(objective_filter_all, get_pagination()) # -->this is where the error is occuring
I checked wheather
objective_filter_all
is a query set or not , and yes indeed objective_filter_all happens to be a query set because It was returningType of objective_filter_all: <class 'django.db.models.query.QuerySet'>
so that means something fishy is going on in this get_pagination() method I did manage to locate this method in methods.py file inside base application here is the methoddef get_pagination(): from base.thread_local_middleware import _thread_locals request = getattr(_thread_locals, "request", None) user = request.user page = DynamicPagination.objects.filter(user_id=user).first() count = 50 if page: count = page.pagination return count
The method seems to be just fine to me , I wonder where the problem is , I think I am missing something , I wonder what?. I also checked the tables just to be sure if there are any inconsistencies in DB through Db viewer but I din't find any I will continue to do my research on this but it would be nice if you could arrange someone who is working on this project so that I can get a better understanding of this project. Thank you! @horilla-opensource
Relevant error screenshotis provided here: NOTE: The error I am getting is similar but if you look into the nitty gritty details then there may be differences because I made some changes into your code and then took the screen shot . But the underlying problem remains the same i.e date or datetime parsing error
Sure, If you want, we can arrange a meeting with the development also.
With Regards, Team Horilla
Oh yes please, how about 7:40 pm according to indian standard time I will only be free after my office hours. Thank you , @horilla-opensource
Sure, I'll check with the team and let you know about it. Meanwhile we'll also figure out the solution for the issue.
With Regards, Team Horilla
Hi @aryan68125 , We have checked the issue and found out that it was an issue caused in the test database. We have updated the test database in the master. You can make use of that for further testing.
With Regards, Team Horilla
Everything seems to be working fine for now. I will let you know if I find something else. Could you please tell me where the mster table is situated in this project, so that I can have look into it myself . Thank you for resolving the issue quickly. @horilla-opensource
Hi @aryan68125 , The test database is located in the project directory itself. The file name is _TestDBHorilla.sqlite3 .
With Regards, Team Horilla
Bug Report
Description
When I try to access dashboard under performance section. I get this error saying ERROR : no such column: pms_employeeobjective.created_by_id
Steps to Reproduce
You just have to follow the installation guide in the docs and then try to go any section under performance tab.
Expected Behavior
created_by_id column should have been created automatically when we run migrations in terminal but for some reason that is not the case
some preliminary digging
created_by_id column is not being created when running migrations. I checked the database via DB_viewer but I couldn't find any column in employeeobjective table . I also chekcked the model of employeeobjective but in there also no created_by_id field is present then I thought that may be I could find something in HorillaModel, and guess what I did find it but with a twist the field that I found is created_by which is doing the same thing as to what created_by_id should have done (according to my understanding I could be wrong though)
Screenshots
Environment
Additional Information
The problem is identified to exist in django_project/HRM/horilla/horilla/models.py HorillaModel --> created_by field **PLEASE CORECT ME IF I AM WRONG ALSO :: IF I AM WRONG THEN please tell me what is the purpose of created_by_id column is when you already have created_by field here which is being inherited by other models in different application via HorillaModel class
Possible Solution
I just went in the database table viaDB Viewer and added a column created_by_id and It started working but this is not the correct solution. I am still trying to understand what is the actual purpose of this
and If it has the same functionality as to what created_by_id would have had ? I am not sure at this moment. I tried changing the created by field name to created_by_id but the entire project just exploded on me so i reverted back. I wonder why pms.dashboard views.py is expecting created_by_id when we already have created by field in horilla model from where the model EmployeeObjective is actually inheriting fom (please explain)
Labels
[If your project uses labels, suggest any labels that might apply to this issue, such as 'bug', 'needs investigation', etc.]
Priority
high
Assignees
[If you want to suggest an assignee or tag a specific person to look into this issue, mention their GitHub username here.]
Related Issues
@horilla-opensource
Note: Remember to search through existing issues before submitting a new one to ensure that the issue hasn't been reported already. Provide as much information as possible to help the maintainers understand and address the problem effectively.