text:
ChatGoogleGenerativeAI doesn't support two system messages.

Checked other resources

[X] I added a very descriptive title to this issue.
[X] I searched the LangGraph/LangChain documentation with the integrated search.
[X] I used the GitHub search to find a similar question and didn't find it.
[X] I am sure that this is a bug in LangGraph/LangChain rather than my code.
[X] I am sure this is better as an issue rather than a GitHub discussion, since this is a LangGraph bug and not a design question.

Example Code
from langchain_core.tools import tool
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
from langchain_google_genai import ChatGoogleGenerativeAI
from langgraph.prebuilt import create_react_agent
from langgraph.prebuilt.chat_agent_executor import AgentState

llm = ChatGoogleGenerativeAI(model="gemini-1.5-flash",)

@tool
def multiply(a: int, b: int) -> int:
   """Multiply two numbers."""
   return a * b

prompt = ChatPromptTemplate.from_messages(
    [
        ("system", "You are a helpful agent. To perform multiplications use the multiply tool."),
        ("user", "Hi, my name is bob"),
        ("system", "hi Bob, nice to meet you."),
        MessagesPlaceholder(variable_name="messages"),
    ]
)

def format_for_model(state: AgentState):
    return prompt.invoke({"messages": state["messages"]})

graph = create_react_agent(llm, tools=[multiply], state_modifier=format_for_model)

inputs = {"messages": [("user", "What's my name?")]}

for s in graph.stream(inputs, stream_mode="values"):
     message = s["messages"][-1]
     if isinstance(message, tuple):
         print(message)
     else:
         message.pretty_print()

Error Message and Stack Trace (if applicable)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[13], line 1
----> 1 for s in graph.stream(inputs, stream_mode="values"):
      2      message = s["messages"][-1]
      3      if isinstance(message, tuple):

File ~\anaconda3\envs\ia\Lib\site-packages\langgraph\pregel\__init__.py:1328, in Pregel.stream(self, input, config, stream_mode, output_keys, interrupt_before, interrupt_after, debug, subgraphs)
   1317     # Similarly to Bulk Synchronous Parallel / Pregel model
   1318     # computation proceeds in steps, while there are channel updates
   1319     # channel updates from step N are only visible in step N+1
   1320     # channels are guaranteed to be immutable for the duration of the step,
   1321     # with channel updates applied only at the transition between steps
   1322     while loop.tick(
   1323         input_keys=self.input_channels,
   1324         interrupt_before=interrupt_before_,
   1325         interrupt_after=interrupt_after_,
   1326         manager=run_manager,
   1327     ):
-> 1328         for _ in runner.tick(
   1329             loop.tasks.values(),
   1330             timeout=self.step_timeout,
   1331             retry_policy=self.retry_policy,
   1332             get_waiter=get_waiter,
   1333         ):
   1334             # emit output
   1335             yield from output()
   1336 # emit output

File ~\anaconda3\envs\ia\Lib\site-packages\langgraph\pregel\runner.py:58, in PregelRunner.tick(self, tasks, reraise, timeout, retry_policy, get_waiter)
     56 t = tasks[0]
     57 try:
---> 58     run_with_retry(t, retry_policy)
     59     self.commit(t, None)
     60 except Exception as exc:

File ~\anaconda3\envs\ia\Lib\site-packages\langgraph\pregel\retry.py:29, in run_with_retry(task, retry_policy)
     27 task.writes.clear()
     28 # run the task
---> 29 task.proc.invoke(task.input, config)
     30 # if successful, end
     31 break

File ~\anaconda3\envs\ia\Lib\site-packages\langgraph\utils\runnable.py:410, in RunnableSeq.invoke(self, input, config, **kwargs)
    408 context.run(_set_config_context, config)
    409 if i == 0:
--> 410     input = context.run(step.invoke, input, config, **kwargs)
    411 else:
    412     input = context.run(step.invoke, input, config)

File ~\anaconda3\envs\ia\Lib\site-packages\langgraph\utils\runnable.py:176, in RunnableCallable.invoke(self, input, config, **kwargs)
    174     context = copy_context()
    175     context.run(_set_config_context, child_config)
--> 176     ret = context.run(self.func, input, **kwargs)
    177 except BaseException as e:
    178     run_manager.on_chain_error(e)

File ~\anaconda3\envs\ia\Lib\site-packages\langgraph\prebuilt\chat_agent_executor.py:566, in create_react_agent.<locals>.call_model(state, config)
    564 def call_model(state: AgentState, config: RunnableConfig) -> AgentState:
    565     _validate_chat_history(state["messages"])
--> 566     response = model_runnable.invoke(state, config)
    567     has_tool_calls = isinstance(response, AIMessage) and response.tool_calls
    568     all_tools_return_direct = (
    569         all(call["name"] in should_return_direct for call in response.tool_calls)
    570         if isinstance(response, AIMessage)
    571         else False
    572     )

File ~\anaconda3\envs\ia\Lib\site-packages\langchain_core\runnables\base.py:3024, in RunnableSequence.invoke(self, input, config, **kwargs)
   3022             input = context.run(step.invoke, input, config, **kwargs)
   3023         else:
-> 3024             input = context.run(step.invoke, input, config)
   3025 # finish the root run
   3026 except BaseException as e:

File ~\anaconda3\envs\ia\Lib\site-packages\langchain_core\runnables\base.py:5354, in RunnableBindingBase.invoke(self, input, config, **kwargs)
   5348 def invoke(
   5349     self,
   5350     input: Input,
   5351     config: Optional[RunnableConfig] = None,
   5352     **kwargs: Optional[Any],
   5353 ) -> Output:
-> 5354     return self.bound.invoke(
   5355         input,
   5356         self._merge_configs(config),
   5357         **{**self.kwargs, **kwargs},
   5358     )

File ~\anaconda3\envs\ia\Lib\site-packages\langchain_core\language_models\chat_models.py:286, in BaseChatModel.invoke(self, input, config, stop, **kwargs)
    275 def invoke(
    276     self,
    277     input: LanguageModelInput,
   (...)
    281     **kwargs: Any,
    282 ) -> BaseMessage:
    283     config = ensure_config(config)
    284     return cast(
    285         ChatGeneration,
--> 286         self.generate_prompt(
    287             [self._convert_input(input)],
    288             stop=stop,
    289             callbacks=config.get("callbacks"),
    290             tags=config.get("tags"),
    291             metadata=config.get("metadata"),
    292             run_name=config.get("run_name"),
    293             run_id=config.pop("run_id", None),
    294             **kwargs,
    295         ).generations[0][0],
    296     ).message

File ~\anaconda3\envs\ia\Lib\site-packages\langchain_core\language_models\chat_models.py:786, in BaseChatModel.generate_prompt(self, prompts, stop, callbacks, **kwargs)
    778 def generate_prompt(
    779     self,
    780     prompts: list[PromptValue],
   (...)
    783     **kwargs: Any,
    784 ) -> LLMResult:
    785     prompt_messages = [p.to_messages() for p in prompts]
--> 786     return self.generate(prompt_messages, stop=stop, callbacks=callbacks, **kwargs)

File ~\anaconda3\envs\ia\Lib\site-packages\langchain_core\language_models\chat_models.py:643, in BaseChatModel.generate(self, messages, stop, callbacks, tags, metadata, run_name, run_id, **kwargs)
    641         if run_managers:
    642             run_managers[i].on_llm_error(e, response=LLMResult(generations=[]))
--> 643         raise e
    644 flattened_outputs = [
    645     LLMResult(generations=[res.generations], llm_output=res.llm_output)  # type: ignore[list-item]
    646     for res in results
    647 ]
    648 llm_output = self._combine_llm_outputs([res.llm_output for res in results])

File ~\anaconda3\envs\ia\Lib\site-packages\langchain_core\language_models\chat_models.py:633, in BaseChatModel.generate(self, messages, stop, callbacks, tags, metadata, run_name, run_id, **kwargs)
    630 for i, m in enumerate(messages):
    631     try:
    632         results.append(
--> 633             self._generate_with_cache(
    634                 m,
    635                 stop=stop,
    636                 run_manager=run_managers[i] if run_managers else None,
    637                 **kwargs,
    638             )
    639         )
    640     except BaseException as e:
    641         if run_managers:

File ~\anaconda3\envs\ia\Lib\site-packages\langchain_core\language_models\chat_models.py:851, in BaseChatModel._generate_with_cache(self, messages, stop, run_manager, **kwargs)
    849 else:
    850     if inspect.signature(self._generate).parameters.get("run_manager"):
--> 851         result = self._generate(
    852             messages, stop=stop, run_manager=run_manager, **kwargs
    853         )
    854     else:
    855         result = self._generate(messages, stop=stop, **kwargs)

File ~\anaconda3\envs\ia\Lib\site-packages\langchain_google_genai\chat_models.py:978, in ChatGoogleGenerativeAI._generate(self, messages, stop, run_manager, tools, functions, safety_settings, tool_config, generation_config, cached_content, tool_choice, **kwargs)
    963 def _generate(
    964     self,
    965     messages: List[BaseMessage],
   (...)
    976     **kwargs: Any,
    977 ) -> ChatResult:
--> 978     request = self._prepare_request(
    979         messages,
    980         stop=stop,
    981         tools=tools,
    982         functions=functions,
    983         safety_settings=safety_settings,
    984         tool_config=tool_config,
    985         generation_config=generation_config,
    986         cached_content=cached_content or self.cached_content,
    987         tool_choice=tool_choice,
    988     )
    989     response: GenerateContentResponse = _chat_with_retry(
    990         request=request,
    991         **kwargs,
    992         generation_method=self.client.generate_content,
    993         metadata=self.default_metadata,
    994     )
    995     return _response_to_result(response)

File ~\anaconda3\envs\ia\Lib\site-packages\langchain_google_genai\chat_models.py:1208, in ChatGoogleGenerativeAI._prepare_request(self, messages, stop, tools, functions, safety_settings, tool_config, tool_choice, generation_config, cached_content)
   1205 elif functions:
   1206     formatted_tools = [convert_to_genai_function_declarations(functions)]
-> 1208 system_instruction, history = _parse_chat_history(
   1209     messages,
   1210     convert_system_message_to_human=self.convert_system_message_to_human,
   1211 )
   1212 if tool_choice:
   1213     if not formatted_tools:

File ~\anaconda3\envs\ia\Lib\site-packages\langchain_google_genai\chat_models.py:445, in _parse_chat_history(input_messages, convert_system_message_to_human)
    432         parts = [
    433             Part(
    434                 function_response=FunctionResponse(
   (...)
    442             )
    443         ]
    444     else:
--> 445         raise ValueError(
    446             f"Unexpected message with type {type(message)} at the position {i}."
    447         )
    449     messages.append(Content(role=role, parts=parts))
    450 return system_instruction, messages

ValueError: Unexpected message with type <class 'langchain_core.messages.system.SystemMessage'> at the position 2.

Description
When running LangGraph agents where the agent's initial set of instructions include two system messages, and the LLM is Gemini (eg. ChatGoogleGenerativeAI), we get a ValueError:

ValueError: Unexpected message with type <class 'langchain_core.messages.system.SystemMessage'> at the position 2.

This behavior doesn't occur if ChatOpenAI is used instead of ChatGoogleGenerativeAI.
My example is quite basic, but the same problem occurs in more realistic usecases such as the Multi-agent supervisor tutorial.
There the prompt template is of this form:
members = ["Researcher", "Coder"]
system_prompt = (
    "You are a supervisor tasked with managing a conversation between the"
    " following workers:  {members}. Given the following user request,"
    " respond with the worker to act next. Each worker will perform a"
    " task and respond with their results and status. When finished,"
    " respond with FINISH."
)

prompt = ChatPromptTemplate.from_messages(
    [
        ("system", system_prompt),
        MessagesPlaceholder(variable_name="messages"),
        (
            "system",
            "Given the conversation above, who should act next?"
            " Or should we FINISH? Select one of: {options}",
        ),
    ]
).partial(options=str(options), members=", ".join(members))

System Info
System Information

OS:  Windows
OS Version:  10.0.19045
Python Version:  3.12.7 | packaged by Anaconda, Inc. | (main, Oct  4 2024, 13:17:27) [MSC v.1929 64 bit (AMD64)]

Package Information

langchain_core: 0.3.15
langchain: 0.3.7
langchain_community: 0.3.5
langsmith: 0.1.139
langchain_chroma: 0.1.4
langchain_experimental: 0.3.3
langchain_google_genai: 2.0.4
langchain_openai: 0.2.5
langchain_text_splitters: 0.3.2
langgraph: 0.2.44
langserve: 0.3.0

Other Dependencies

aiohttp: 3.10.10
async-timeout: Installed. No version info available.
chromadb: 0.5.17
dataclasses-json: 0.6.7
fastapi: 0.115.4
google-generativeai: 0.8.3
httpx: 0.27.0
httpx-sse: 0.4.0
jsonpatch: 1.33
langgraph-checkpoint: 2.0.2
langgraph-sdk: 0.1.35
numpy: 1.26.4
openai: 1.53.1
orjson: 3.10.11
packaging: 24.1
pillow: Installed. No version info available.
pydantic: 2.9.2
pydantic-settings: 2.6.1
PyYAML: 6.0.2
requests: 2.32.3
requests-toolbelt: 1.0.0
SQLAlchemy: 2.0.35
sse-starlette: 1.8.2
tenacity: 9.0.0
tiktoken: 0.8.0
typing-extensions: 4.11.0

@andressilvac having multiple system messages is not necessary to implement the supervisor architecture -- we'll be updating the tutorials to simplify this! are there any other reasons why you need 2 system messages besides the tutorial?

Thanks. So far, not really, I guess I can work without multiple system messages. Thanks.

@andressilvac You can also use langraph if you want to use multiple agents.

authors: andressilvac keenborder786 vbarda


text:
VectorStore add embedded texts interface

Feature request
Add a way to pass pre-embedded texts into the VectorStore interface.
Options:

Standardize the add_embeddings function that has been added to some of the implementations. e.g.

    def add_embeddings(
        self,
        texts: List[str],
        embeddings: List[List[float]],
        metadatas: Optional[List[dict]] = None,
        **kwargs: Any,
    ) -> List[str]:

Add embeddings kwarg to the add_texts interface

    def add_texts(
        self,
        texts: Iterable[str],
        metadatas: Optional[List[dict]] = None,
        embeddings: Optional[List[List[float]]] = None,
        **kwargs: Any,
    ) -> List[str]:

First option is nice in that it leaves each function with a very distinct role, but has added overhead for implementing the interface. Results in very similar code between add_texts and add_embeddings and/or a third private method to handle the actual add operation.
Second option should be pretty straightforward to add to all the implementations, but adds some clutter to the add_texts interface. No too bad IMO as it would be handled almost the same as metadatas.
Motivation
Embedding a large body of text (e.g. pubmed) takes a long time, and it is too restrictive to rely on each VectorStore implementation calling embedding functions in the most optimal way every use case. By having a defined way to pass in embeddings directly the interface becomes much more flexible.
For example I've been using huggingface's Datasets.map for processing texts, running embeddings on multiple gpus, etc. Would like to be able to save the final embedded dataset, and then insert into the vector store.
Your contribution
Happy to help work on it. I know there's quite a few vector store implementations that would have to be updated for this.

In Milvus, these is pretty easy. Look at this page
https://milvus.io/docs/v1.1.1/insert_delete_vector_python.md

Great! I expect most should be straightforward to implement. I would be shocked if there is a vector store that doesn't support this.

Yeah, decoupling the embedding process and the indexing process would help!

Still relevant

source: gharchive/issue

authors: GomathyDhanya bhperry talhaanwarch

repo: langchain-ai/langchain

license: MIT

license_type: permissive

license_source: github-api


text:
Multi-modal RAG template

OpenCLIP embeddings
GPT-4V

https://smith.langchain.com/public/007ba159-3549-4286-b4c0-91c4ad7c4310/r

Right, prompt tokens are > 100k.
1/ It looks like it retrieves 4 images here.
2/ But, as expected, we restrict to at max 2 images in the prompt.
3/ Those 2 are passed to GPT-4V here, which reports 111,332 tokens.
4/ Previously, I passed the same 2 images here, and GPT-4V reports 2,504 tokens.
The image size should be consistent; before I also used size=(1280, 720).
This is a weird bug that I have noticed before, but have not been able to root-cause yet.
It appears non-deterministic.

May want to wait until image prompt template is in.

source: gharchive/pull-request


text:
PostgreSQL Configuration in Docker via .env Not Applied

I'm encountering an issue with configuring PostgreSQL within a Docker container using environment variables specified in a .env file. Despite updating the repository and setting the PostgreSQL configuration in the .env file, the changes don't seem to be applied, leading to errors when starting the container.
Environment Configuration (.env):
POSTGRES_PORT=5432
POSTGRES_DB=opengpt
POSTGRES_USER=opengpt
POSTGRES_PASSWORD=opengpt

Steps to Reproduce:

Update the repository to include the above PostgreSQL configuration in the .env file.
Remove existing Docker images and containers to ensure a clean state.
Rebuild and start the Docker containers using the updated .env file.

Expected Behavior:
The PostgreSQL container starts with the specified configuration, allowing other services to connect using the provided credentials and database name.
Actual Behavior:
The PostgreSQL container logs indicate that it skips initialization due to an existing database directory, and subsequent logs show errors related to the database not existing and password authentication failing for user "opengpt".
Error Logs:
ttaching to opengpts-backend, opengpts-frontend, postgres-1, postgres-setup-1
postgres-1         |
postgres-1         | PostgreSQL Database directory appears to contain a database; Skipping initialization
postgres-1         |
postgres-1         | 2024-03-21 08:42:30.789 UTC [1] LOG:  starting PostgreSQL 16.2 (Debian 16.2-1.pgdg120+2) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
postgres-1         | 2024-03-21 08:42:30.789 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
postgres-1         | 2024-03-21 08:42:30.789 UTC [1] LOG:  listening on IPv6 address "::", port 5432
postgres-1         | 2024-03-21 08:42:30.795 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres-1         | 2024-03-21 08:42:30.803 UTC [29] LOG:  database system was shut down at 2024-03-21 08:41:51 UTC
postgres-1         | 2024-03-21 08:42:30.809 UTC [1] LOG:  database system is ready to accept connections
postgres-1         | 2024-03-21 08:42:31.810 UTC [40] FATAL:  database "opengpt" does not exist
postgres-1         | 2024-03-21 08:42:32.466 UTC [41] FATAL:  password authentication failed for user "opengpt"
postgres-1         | 2024-03-21 08:42:32.466 UTC [41] DETAIL:  Connection matched file "/var/lib/postgresql/data/pg_hba.conf" line 128: "host all all all scram-sha-256"
postgres-setup-1   | error: pq: password authentication failed for user "opengpt"
postgres-setup-1 exited with code 1
service "postgres-setup" didn't complete successfully: exit 1

Additional Information:

I've tried varying the .env values and ensuring that there are no typos or errors in the variable names.
The issue persists even after cleaning Docker images and containers to ensure there's no stale configuration.

Any insights or suggestions on resolving this issue would be greatly appreciated.

Given the fact that logs show PostgreSQL Database directory appears to contain a database; Skipping initialization, I believe that you already initialized the database with other env vars than the ones you are currently trying to use. Here's what to try: delete the postgres-volume and run docker again. Should work.

authors: bakar-io shamspias

repo: langchain-ai/opengpts


text:
[BUG] DocumentByParagraphSplitter does not split properly when \r\n line endings are used

It seems that \r\n is treated as a paragraph separator, which is wrong

I found that there are different performances under JDK8 and JDK17

Java HotSpot(TM) 64-Bit Server VM (build 25.241-b07, mixed mode)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.9+11-LTS-201, mixed mode, sharing)

public static void main(String[] args) {
    String s = "Hello\r\nWorld";
    String[] split = s.split("\\s*\\R\\s*\\R\\s*");
}

There is a discussion on similar issues here
https://stackoverflow.com/questions/47871962/why-does-r-behave-differently-in-regular-expressions-between-java-8-and-java-9

In other words, it can only match a two code-point CR+LF (carriage return + linefeed) sequence or else a single code-point from that set provided that it is not just a carriage return alone that is then followed by a linefeed. That’s because it is not allowed to back up. CRLF must be atomic for \R to function properly.
So Java 9 no longer conforms to what R1.6 strongly recommends. Moreover, it is now doing something that it was supposed to NOT do, and did not do, in Java 8.

I replaced //R to (?>\\R) according to the suggestions in the document
It can work normally in both versions


text:
[PoC] Allow to programmatically plug message in the AiServices

This pull request is a variation and simplification of what I proposed here. As anticipated there instead of making the AiServices aware of the concept of a state machine I simply added the possibility of making the system and user messages configurable in a programmatic way. Currently this pull request has the same limitation of the other one: lack of the possibility of configuring messages for each user/conversation and of support of tools, but I believe that both things could be added once we agree on the main direction.
I tried this pull request and the other with the same use case that I implemented here and both produce an output similar to the following:
User: hi
Agent:  Hello! May I please have your full name for our records? And could you kindly share your age with me as well? Thank you.
User: My name is Mario Fusco and I'm 70
Extracted Customer { firstName = "Mario", lastName = "Fusco", age = 70 }
Agent:  Hello Mario, thank you for sharing your name and age. Could you please tell me which flight you recently took with us, including the flight number? Also, was there any delay in your flight? If so, could you provide the approximate duration of the delay? Thank you.
User: I was on flight 22 and it had a delay of 4 hours
Extracted Flight { number = "22", delayInMinutes = 240 }
Agent: Thank you Mario Fusco, you are eligible for a refund of $528.0

@langchain4j I updated this pull request following your suggestions. Please let me know if I'm missing something.

That said I believe that you're mixing things at 2 different levels or at least this is how it works in the integration use case that I provided with this pull request. When you use one of the 2 methods that I added to the AiServices you are not defining a complete message but only a template for it.

Yes, I do not make a clear distinction between the complete message and a template. At least for me it is kind of the same thing. If there are placeholders, replace them with values and go futher. If no placeholders - ok, just send it as-is. Maybe I am wrong and majority of users see it differently and want a clear distinction...
Currently, when you do like this, the string in the annotation is treated as a template:
@UserMessage("What is the capital of {{it}}?")
String chat(String country);

But when you do like this, the userMessage is not treated as a template, which I think is a bug.
String chat(@UserMessage String userMessage, @V("country") String country));

Some people expect that userMessage in this case should be treated as a template, and I think I agree.
So, when this bug is fixed, one can supply template directly into the method, without a need in userMessageProvider.

But when you do like this, the userMessage is not treated as a template, which I think is a bug.
String chat(@UserMessage String userMessage, @V("country") String country));

Some people expect that userMessage in this case should be treated as a template, and I think I agree. So, when this bug is fixed, one can supply template directly into the method, without a need in userMessageProvider.

I agree that what you described is a bug (or a missing feature) and has to be fixed.
I disagree (but I understand that this is more questionable and a matter of tastes and opinions) that this replaces the need of userMessageProvider. To me with the userMessageProvider I'm configuring the general behavior of the agent, that can change at a later stage when the application reaches a different state, while when I invoke agent.chat(userMessage) I'm just conveying the actual message received from the end-user to an agent that has been pre-configured to treat the user's message as she expects.
In essence I'd prefer having a clear separation between the agent configuration and its usage, as allowed by the userMessageProvider, but I understand that this introduced some additional complexity and it's up to you to decide if it is justified or not. In case you decide to keep this feature and need an help to increase its test coverage just let me know.

To me with the userMessageProvider I'm configuring the general behavior of the agent, that can change at a later stage when the application reaches a different state, while when I invoke agent.chat(userMessage) I'm just conveying the actual message received from the end-user to an agent that has been pre-configured to treat the user's message as she expects.

I see what you mean, but to configure the general behavior of the agent, system message is usually used. User message is an actual message from the user and it theory should not contain any instructions on how the agent should behave.
With this in mind, I would expect user message to be supplied directly to the agent as a method argument. And system message via @SystemMessage annotation or systemMessageProvider.

In essence I'd prefer having a clear separation between the agent configuration and its usage, as allowed by the userMessageProvider

I agree on "having a clear separation between the agent configuration and its usage", but for the "agent configuraton" I would expect system message and for "its usage" - user message.

I understand that this introduced some additional complexity and it's up to you to decide if it is justified or not.

I already see how this becomes more an more complicated, so I would prefer to reduce the complexity where possible. For now I propose to keep systemMessageProvider and remove userMessageProvider, we can always bring it back if needed. Hope you are ok with this.

In case you decide to keep this feature and need an help to increase its test coverage just let me know.

Thanks a lot, but no worries, I am already finalizing this

I already see how this becomes more an more complicated, so I would prefer to reduce the complexity where possible. For now I propose to keep systemMessageProvider and remove userMessageProvider, we can always bring it back if needed. Hope you are ok with this.

Big +1 on this! I was speaking about the user and system messages in an interchangeable way and assuming that my considerations were valid for both, but indeed they are 2 different things with different purposes and indeed what I needed to configure with the state machine in my PoC is the system message.


text:
🚀 : Nicknames

Idea
When messaging with a lot of people, it can be really hard to keep a lot of names straight, even for those who are really good with names (I am not one of those people!). Therefore, I think being able to add custom "nicknames" for people would be a valuable feature.
Benefits
As mentioned above, it can be hard to keep track of names, therefore, a nickname of your choosing might be away to get around that problem. Take a user named Bob for example. You guys are both learning Spanish, so your chats consist of a lot of Spanish with some English mixed in to help each other out. Now let's say you have a lot of other people your messaging, each in a different language, or one of them is just a friend you found and your both speaking in your native tongue. You want to be able to quickly distinguish between what languages or what kind of conversations your having with different users. That's why nicknames would help. Instead of a person named Billy, you could nickname them Billy (Spanish), or Billy (Friend), or Billy (Economics), making it much easier to tell who you are really talking to.
Implementation
The nicknames would be implemented so that each was private and visible only to the person who assigned the nickname. The user who has been assigned the username would not be able to see it.

I think it's duplicate of #757

Hey Xue, I think you may have misunderstood? I meant you could assign custom names to people, not search up people by tags. Sorry if I'm wrong.

Hey @xuelink , I think you may have misunderstood? I meant you could assign custom names to people, not search up people by tags. Sorry if I'm wrong.

I got what you mean thats why i updated my comment to related instead of duplicate :D

[ ] Renaming Name to Display Name is going to close this issue.

repo: langx/langx


text:
Inconsistent definitions error

Building on Mac (but could also simply be a highs version issue?)
brew install pkg-config
brew install highs

$ pkg-config highs --cflags --libs
-I/opt/homebrew/Cellar/highs/1.7.2/include/highs -L/opt/homebrew/Cellar/highs/1.7.2/lib -lhighs

Installing highs go package:
$ go install github.com/lanl/highs
# github.com/lanl/highs
cgo: inconsistent definitions for C.kHighsObjSenseMinimize
cgo: inconsistent definitions for C.kHighsHessianFormatTriangular
cgo: inconsistent definitions for C.kHighsObjSenseMaximize

I looked into this, and it appears that it's not a HiGHS version issue but rather a GCC vs. Clang issue.  Clang, which is the default compiler on Mac, seems to be more pedantic than GCC.  I compared GCC 13.2.0 and Clang 18.1.3, both on Ubuntu 24.04.  go build (GCC) works, but env CC=clang go build (Clang) gives the same "inconsistent definitions" errors you report above.
I believe I can fix the problem by redeclaring all of the HiGHS variables and functions instead of using the HiGHS header files directly.  Stay tuned…

Now it works, thanks @spakin !

authors: bartolsthoorn spakin

repo: lanl/highs


text:
cmake config guard for submodule mode

PR Summary
If used as in-tree as a submodule downstream, cmake will include() a file generated by export(), which generates an error (see https://cmake.org/cmake/help/v3.17/policy/CMP0024.html). This includes a guard against invoking the include() in the scenario when ports-of-call is not the main project.

This fixes an issue encountered when singularity-eos cmake configuration was re-run after the initial cmake generate step. In this case, importing spiner submodule would use the prior export()-ed ports-of-callConfig.cmake that was present in the build directory. Due to CMP0024 (above), this would produce an error, and the build directory would need to be cleaned to produce a usable configuration.

PR Checklist

[x] Any changes to code are appropriately documented.
[x] Code is formatted.
[ ] Install test passes.
[ ] Docs build.

@mauneyc-LANL let me know when all tests pass and I will merge. Can't run tests myself at the moment.

@mauneyc-LANL let me know when all tests pass and I will merge. Can't run tests myself at the moment.

I'm not seeing any tests for this code.

I thought there was an install test. Well no big deal either way.

The install test passed. Merging.

No problem.

authors: Yurlungur mauneyc-LANL

repo: lanl/ports-of-call


text:
Support laravel-websockets (pusher-compatible)

This is  a feature request.

Prerequisites

[x] Are you running the latest version?
[x] Are you reporting to the correct repository?
[x] Did you check the documentation?
[x] Did you perform a cursory search?

Description

adding host & port configurations to echo/pusher instances makes it compatible with Laravel-Websockets, a self-hosted pusher alternative that includes a compatible API
docs
Notable changes
add a host & port option to config/broadcast.php, ex.:
            'options' => [
              'host' => env('PUSHER_APP_HOST', 'api.pusherapp.com'),
              'port' => env('PUSHER_APP_PORT', 6001),
              ...

when instantiating an Echo (currently in IO.vue & Notifications.vue), add a wsHost & wsPort option. disableStats should also be set to true as this would keep sending client-side stats to pusher.
ex.: (extra meta attributes would need to be forwarded)
                wsHost: this.meta.pusherHost,
                wsPort: this.meta.pusherPort,
                disableStats: true,

Sorry we had more pressing issues coming up.
I've just rounded up implementing & testing the laravel-websocket implementation so I should be able to PR the changes later this week.
We had some initial hiccups, mostly related to SSL; but fixed them by using a proper production strategy (reverse-proxy); I'll add important notes to the PR code and/or docs.

repo: laravel-enso/Notifications


text:
Help disable eslint checks

This is  a help request.

Prerequisites

[x ] Are you running the latest version?
[ x] Are you reporting to the correct repository?
(enso is made of many specialized packages: https://github.com/laravel-enso)
[ x Did you check the documentation?
[x ] Did you perform a cursory search?

Description
The Eslint checks are giving us a lot of errors especially with line endings, curly braces, line length and so on.
Is there an easy way to disable eslint from doing this? .eslintignore file seems to be ignored.
Also modifying the eslint rules doesn't seem to do the trick either...
Steps to Reproduce

Update to enso 3.7.2
Build the assets
Yarn watch
Change some .vue or .js files
In many cases eslint raises errors and the build crashes

Expected behavior
We want to disable eslint and use our project code formatting.
Actual behavior
Eslint complains about formatting and the builds are constantly crashing.

You can call the linting with --fix - then most of the errors are fixed automatically.
(I had 1.300 errors and the --fix solved ~1.220 of them)

Yes, I already tried that, and the build is ok but when I run "yarn build--watch" and change one file, then is constantly crashing again.., even if I try also with "yarn build --watch --fix"

I think it should be changed from errors to warnings - but I'm also beginner in this topic.

I already tried that in eslintrc file but it didn't work, because many
rules are  inherited from vue itself.
On Fri, 22 Nov 2019, 12:09 mauthi, notifications@github.com wrote:

I think it should be changed from errors to warnings - but I'm also
beginner in this topic.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/laravel-enso/enso/issues/270?email_source=notifications&email_token=AN23K2QEVFRSRQ6H722Y223QU6VXBA5CNFSM4JQOJXF2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEE5FZKY#issuecomment-557472939,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AN23K2RQJVAYXW6T5NLDADLQU6VXBANCNFSM4JQOJXFQ
.

You will have to modify (in sync) both eslint files and setup your personal rules. The one in the root folder, used by editors, and the one in under the client folder used by vue cli service.

Regardin the rules inherited from vue, it was one of the main reasons why it took so long for us to migrate on vue cli. But eventually we conformed with them.

You will have to modify (in sync) both eslint files and setup your personal rules. The one in the root folder, used by editors, and the one in under the client folder used by vue cli service.

Thanks for this explanation, I did not understand from the documentation which eslint file is used or not and for what purpose. Can you add this mention on documentation also? It can save a lot of time for any others that have these issues. I spent precious time trying to understand why my rules are working in some cases and not working in other ones

@gandesc please add a mention regarding this in docs.

Thank you!
On Fri, 22 Nov 2019, 12:51 Adrian Ocneanu, notifications@github.com wrote:

@gandesc https://github.com/gandesc please add a mention regarding this
in docs.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/laravel-enso/enso/issues/270?email_source=notifications&email_token=AN23K2T5YP7BUNMAJX4QRELQU62TBA5CNFSM4JQOJXF2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEE5JCAA#issuecomment-557486336,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AN23K2SH2WF3CKDGNHDLABLQU62TBANCNFSM4JQOJXFQ
.

authors: adithewonderboy aocneanu mauthi

repo: laravel-enso/enso


text:
Update TailwindCSS version

Just wanted to keep the Tailwind version up to date

I'll leave it for now, seeing as 1.0 is right around the corner (acknowledging that you submitted this PR a month ago - sorry, been busy!)

repo: laravel-frontend-presets/tailwindcss


text:
BCC recipients became visible with Mailgun driver

I am using the Mailgun driver in Laravel 5.1. We're sending out group emails and would like the recipients to be hidden via BCC.
After switching from Mandrill to Mailgun, BCC recipients became visible in some clients, including Gmail. The code we use in Laravel to send the email has not changed.
Mail::send('emails.group-email', $data, function($message) use ($data) {
            $message->to('support@example.com');
            $message->bcc($this->recipients); // Contains an array of emails
            $message->subject('FVRS Group Email - ' . $this->subject);
        });

Confirm the problem is present.
Laravel uses to parameter to pass all recipients to Mailgun, while CC and BCC separating is made in message headers. This makes BCC visible in message source code - so Gmail displays it.
There is additional info in examples which shows that bcc parameter can be passed.
I've tested it manually and there is a way to make it work with Laravel.

Fixed.

This issue still persist (using Laravel 5.1)

authors: GrahamCampbell enVolt nilay rkgrep

repo: laravel/framework


text:
url helper not picking the base root from the config setting

Laravel Version: 5.3.22
PHP Version: 7.0
Database Driver & Version: N/A

Description:
When using the url helper, the root is calculated by symfony and not picked up according to the APP_URL env variable.
I found out about it when I was trying to use the url helper in an email notification which was sent based on an eloquent event listener (placed in a service provider) while running the app on homestead. The helper didn't pick up the 8000 port. After checking it I noticed the helper is using the request root function which is calculating the root based on a prepareBaseUrl symfony function (look here: https://github.com/laravel/framework/blob/5.3/src/Illuminate/Http/Request.php#L87, while the getBaseUrl is calling prepareBaseUrl), and that function somehow miss the port number in this specific call (from a service provider). So even when I manually set the 8000 port on the APP_URL env variable, nothing changed.
Note - when the email notification was called regularly from a controller, the port was received correctly. It only happened to me when the notification was called from a service provider.
Also, I believe on production there shouldn't be a problem as you don't need a special port like when using homestead.
Steps To Reproduce:

Create a laravel app locally on homestead.
Create a mail notification and place a url() helper call in it to some link or asset.
Create an eloquent event listener in a service provider (for example appServiceProvider (for example a listen to a model creation event) which then sends the email notification.
Create that model to invoke the listener and the notification sending.
Look at the returned URL created with the url helper and see there is no 8000 port.

The base URL is auto detected, it's not meant to be picked from the config file.
I'm using valet now but I don't think I ever had any problem with ports when I was on Homestead, it used to pick it up with no problem, it's also strange that it works from within a controller but not a listener.

I guess this is a queued listener. Fix will be to make it not queued, and only the queue sending part, after the content has been computed. If you're rendering a view to do that, you'll need to upgrade to L5.4, because it renders the view before queuing, unlike 5.3, (I think, you'll need to check this in the laravel source code).

@GrahamCampbell nope, not queued. So it's a different bug. Try to reproduce and you'll see it too.

@amosmos any progress on this?

No, nothing really changed... The route() function is based on symphony's prepareBaseUrl which just misses the port when the call is from a service provider. You can just reproduce it and see it too... I don't know how to fix this...

Can you try what i posted #14139 ?

@amosmos , alternatively you can replace \Illuminate\Foundation\Bootstrap\SetRequestForConsole class and change bootstrap method to be as in https://github.com/laravel/framework/issues/14139#issuecomment-323409775 comment of mine.

Anyone managed to fix this issue?

authors: GrahamCampbell aik099 amosmos mtx-z ronnyandre themsaid


text:
jQuery is not defined after migrating to Laravel 5.4

Laravel Version: 5.4.6
PHP Version: 7.0.13

Description:
After migrating to Laravel 5.4 => javascript bug => ReferenceError: jQuery is not defined
(With Elixir in 5.3 everything works fine.)
This variable is defined in asset/js/bootstrap.js
window.$ = window.jQuery = require('jquery');
in javascript console, i see "$" is correctly defined and a variable name jQuery311052537473254022181 is define...
Seem to be a suffix added ... A bug of wepack config of laravel.mix ???
Steps To Reproduce:
Make a simple javascript closure like
function()({  ... })(jQuery);
then compile assets with command "npm run dev" (same thing with npm run production).
When you try the javascript closure => jQuery is not defined.

Thanks @tabirkeland, that did it for me! I'm no JavaScript wizard, could you explain why $ would be available globally but not jQuery, even though they are both being assigned to window?

I also had this same problem and the above fixed.

I am having the same issue with Framework 5.4.15, but the above fix does not work.

Same issue. Fix does not work =(

Same error in my fresh 5.4.21, I fixed it using:

delete window.$ = window.jQuery = require('jquery') in bootstrap.js;
in webpack.mix.js add
mix.webpackConfig({
resolve: {
alias: {
jquery: "jquery/src/jquery"
}
}
});

This issue is not yet resolved. Not sure why this was closed?

If this is happening inside a child vue component you can add this to that component script and it will work
window.$ = window.jQuery = require('jquery');

@mhulu solution solved my issue.

@tabirkeland not work for me :(
@mhulu please mention file location ? where we add this code.
No idea about this file location.

tabirkeland solution did not work for me either.  I researched Laravel Mix a bit, but didn't want to head down that road just yet.
I found the file /public/js/app.js which appears to contain all of the required js, including jquery.
This appears to be built from /resources/assets/js/app.js by Laravel Mix webpack.mix.js:
mix.js('resources/assets/js/app.js', 'public/js')
.sass('resources/assets/sass/app.scss', 'public/css');
I noticed that in /resources/views/layouts/app.blade.php the
was the last tag in the  tag.
I moved this

All, Mix has been updated extensively since my solution was posted.  I would suggest going with @mhulu solution by modifying your webpack.mix.js and aliasing JQuery.

Yo all. I've just been playing about with this. My problem disappeared when I stopped trying to extract bootstrap's into the vendor's.js.
I'm no js Supremo, but I'm guessing that's where a lot of people's problems might be coming from, it's an obvious file to want to extract, It still looks like a bug to me, but hopefully that'll help someone track it down a bit more accurately.

Yes @Sam-WWHC! When i stopped of try extract the jquery from node_modules path the problem disappeared! Thanks!

You can extract, but you'll need to autoload as well if you're using any scripts that expect it to be available globally.
https://github.com/JeffreyWay/laravel-mix/blob/master/docs/autoloading.md
Be sure to only call autoload once and include everything you need autoloaded. Subsequent calls to autoload seem to overwrite previous calls.

thanks @devcircus ! after adding 'jQuery' to the autoload the extraction works as expected again.
after some recompilations the autoload directive randomly suddenly seemed to make a difference. threw some other errors before that - does webpack cache so hard that it needs several recompilations?
the order in which the extractions are defined doesn't matter, right?
mix.js('resources/assets/js/app.js', 'public/js')
    .extract([
        'axios',
        'blazy',
        'bootstrap',
        'd3',
        'jquery',
        'js-cookie',
        'laravel-echo',
        'localforage',
        'localforage-startswith',
        'moment',
        'nvd3',
        'responsive-toolkit',
        'socket.io-client',
        'vue',
        'vue-echo',
        'vue-moment',
        'vue-strap',
        'vuedraggable'
    ])
    .autoload({
        jquery: ['$', 'window.jQuery', 'jQuery'],
    });

@muhulu
you save my life

Laravel 5.5
@UniquelySimilar  thanks your solution works, it's not good to move js file in the header but it fixed my issue.
The issue is "app.js" loaded at the end of the file and I need some jquery code in register view so I was getting jquery undefined.
I used @mhulu  solution but after changing mentioned files and after refresh the folder not worked maybe I need to rebuild app.js again, I don't know how to rebuild app.js :)

@shahzadthathal just to clarify, I suggested moving the script tag to the top of the body tag, not into the head tag.
However, opinions of where to place script tags can vary, like many other ideas in the programming world:
https://stackoverflow.com/questions/3531314/should-i-write-script-in-the-body-or-the-head-of-the-html
I'm not interested in starting a discussion or debate, as it is off the subject of this issue.  Whatever works for a specific situation.

I found a solution for me with something similar to what you wrote. @UniquelySimilar but i didn't put the script tag for app/js on top of body, i put it at the end. Whatever works.

@RPJ18 thanks for the update.  I recently started working with Vue.js and WebPack, and if doing it again would probably try to resolve this issue with Laravel Mix/WebPack rather than moving the script tag, but it worked for me at the time.

I have been experiencing this issue as well and I found myself the cause of the problem was "defer" attribute in script addition of app.js

this "defer" tag was forcing script to load only after page was loaded. So I simply put the same attribute to the other js file addition as well where I needed jQuery and of course put it below the app.js addition.
This way both script loaded after page has completed loading and as app.js came before, it made jQuery available to my other script.
Maybe helps someone.

None of the above worked for me. I solved this issue by adding the following:
mix.webpackConfig(webpack => {
  return {
	        plugins: [
	            new webpack.ProvidePlugin({
	                $: 'jquery',
	                jQuery: 'jquery',
	                jquery: 'jquery',
	               'window.jQuery': 'jquery'
	        })
	    ]
      };
  })

mix.autoload is supposed to do the same internally but it somehow isn't working as expected for me. This is the only way I could extract Bootstrap without getting jQuery is not defined error.
P.S. found this here: https://stackoverflow.com/questions/49351415/laravel-mix-uncaught-referenceerror-jquery-is-not-defined

I was having the same problem in laravel 5.7, I tried some solution above did not work,
For me adding type="text/javascript" solved the problem.
Before <script src="{{ asset('js/app.js') }}"></script>  did not work.
Now <script src="{{ asset('js/app.js') }}" type="text/javascript"></script> this solved my day, but I don't know why.

Faced the same problem. For me, it was defer loading app.js in the header was creating the issue.
Moved to the footer, removed defer, and added inline script below that. It worked :-)
<script src="{{ asset('js/admin.js') }}"></script>
@yield('local_script')

I fixed by just removing "defer" from script tag.
My laravel 5.7 installation included  <--- this tag, so i removed the defer as i mentioned before by just leaving  like that... It fixed now =)

@steve5287 I too was able to solve the $ reference error by removing defer however, I now have an error about Vue not being able to find #app
Did you run into this same issue?
Also, what is the underlying issue here? It seems rather odd that a vanilla Laravel app would have such difficulty using jQuery in a Blade template.

@steve5287 I too was able to solve the $ reference error by removing defer however, I now have an error about Vue not being able to find #app
Did you run into this same issue?
UPDATE: Just moving things around, and putting <script src="{{ asset('js/app.js') }}"></script> at the end of my layout Blade, before the scripts section has solved both issues. Would still like to know how to get this working without modifying the vanilla templates, if possible.
Also, what is the underlying issue here? It seems rather odd that a vanilla Laravel app would have such difficulty using jQuery in a Blade template.

I also moved the app.js tag at the end of the blade template. Don't know why they put it at the top "head" tag. Still having problems?

None of these solutions work for me :(

Please re-check if you have added defer in your app script or not.
If you have used laravel-mix and added jQuery there make sure your app.js dont have a defer attribute

using Laravel 8 in Dec 2020, same issue here.
I could solve with @tuhin-paul solution
putting
mix.webpackConfig(webpack => {     return {         plugins: [             new webpack.ProvidePlugin({                 $: 'jquery',                 jQuery: 'jquery',                 jquery: 'jquery',                 'window.jQuery': 'jquery'             })         ]
in webpack.mix.js, then npm run watch (or dev).
Also removing "defer" in app.js raw in blade, and moving all of my js after it.

Using Laravel 8, 19-Jan 2021.
tried all of these methods and nothing seem to work. I added @tuhin-paul code to all 4 of my webpack.mix.js and run 'npm run watch' but the error is still there.
I have no idea what to do next. https://ibb.co/ccvjR6n

Using Laravel 8, 19-Jan 2021.
tried all of these methods and nothing seem to work. I added @tuhin-paul code to all 4 of my webpack.mix.js and run 'npm run watch' but the error is still there.
I have no idea what to do next. https://ibb.co/ccvjR6n

This could help!
var ready = (callback) => {
if (document.readyState != "loading") callback();
else document.addEventListener("DOMContentLoaded", callback);
}
then use this function like this
ready( () => {
( function() {
'use strict';
})(jQuery);
});
works perfectly for me

authors: ABTanjir Christophvh DominiqueFERET Karu272 LarBearrr RPJ18 Sam-WWHC SpiderFelix UniquelySimilar abhaymaurya andymnc devcircus ggwebdev gustav1105 joval-sv luchaos mailnike mhulu mohamedhakika nejtr0n omatamix rameshnavi rappasoft reinink shahzadm287 shahzadthathal steve5287 tabirkeland tuhin-paul vaxilicaihouxian


text:
withThrashed() method on routes with explicit model binding does not resolve trashed models

Laravel Version: 9.19.0
PHP Version: 8.1.7
Database Driver & Version: MySQL 8.0.28 / mysqlnd 8.1.7

Description:
The withThrashed() method on routes with explicit model binding does not seem to resolve trashed models. Trashed models will produce a not found error; non-trashed models are unaffected. withTrashed() on routes with implicit binding is working as expected.
An issue concerning the exact opposite seems to have been reported some time ago:  #39799 - I'm not sure if there's any relation though.
Steps To Reproduce:
Simplified code for reproduction:
The explicit binding part in RouteServiceProvider.php
Route::bind('post', function ($value) {
    return Post::where('id', $value)->firstOrFail();
});

routes\web.php
use App\Models\Post;

Route::get('/post', function () {
    $post = Post::create([]);
    return $post->id;
});

Route::get('/post/{post}', function (Post $post) {
    return $post->id;
});

Route::get('/post/{post}/delete', function (Post $post) {
    $post->delete();
    return 'Deleted';
});

Route::get('/post/{post}/restore', function (Post $post) {
    $post->restore();
    return 'Restored';
})->withTrashed();

app\Models\Post.php
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\MassPrunable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Post extends Model
{
    use HasFactory, SoftDeletes, MassPrunable;
}

Migration
public function up()
{
    Schema::create('posts', function (Blueprint $table) {
        $table->id();
        $table->softDeletes();
        $table->timestamps();
    });
}

Hey @Thomas14 when you use the Route::bind method you are telling laravel to resolve your route model binding using whatever callback you provide to that method. You can check line 854 of Illuminate/Routing/Router class:
https://github.com/laravel/framework/blob/95ce178cbde9f9f38013862f677a5314da67af85/src/Illuminate/Routing/Router.php#L852-L861
Basically, if there is a bind for the given key, then laravel will use performBinding method and call the callback you provided with Route::bind to resolve the model:
https://github.com/laravel/framework/blob/95ce178cbde9f9f38013862f677a5314da67af85/src/Illuminate/Routing/Router.php#L887-L890
So, in order to get trashed models, you need to use withTrashed in your query within the provided callback.
If you change your Route bind to to the code below then it will work:
Route::bind('post', function ($value) {
    return Post::withTrashed()->where('id', $value)->firstOrFail();
});

Hope it helps.

Hi @mateusjunges
Whoops... that makes a lot of sense. Intuitively I expected withTrashed on the route to affect the query in the same way it does with implicit binds without giving it any further thought (yikes), I somehow managed to completely overlook the fact that with the callback I am of course building the query myself... oh the simple things I miss sometimes... this was an incredibly silly oversight on my part, sorry!
Thanks for your help :)


text:
$request->user() or Auth::user run query each time if token doesn't exists

Laravel Version
10.34.2
PHP Version
8.2.12
Database Driver & Version
8.2.0
Description
sanctum version : 3.3.2
Hi, I use Laravel with Sanctum, and I've noticed that the app runs a query each time I use request()->user()

I found that if the saved token is incorrect or doesn't exist in the database, the user resolver runs a query each time it is called, and this is not good for performance.
Steps To Reproduce
you can run a fresh Laravel app with sanctum and set wrong token in Bearer token that not exist and use request()->user() for times.
I check app and query log with Clockwork browser extension.

@taylorotwell decided to get along with this behavior on #49205, we won't wix

You should check through Auth::hasUser() after your first call for Auth::user() (available since 5.6)

https://github.com/laravel/framework/pull/24518

Thanks @mpyw
@mnr73 please see the above.

thanks. I handled this 🙏

authors: driesvints mnr73 mpyw


text:
php artisan test super slow after updating to v10.34.2 from v10.33.0

Laravel Version
10.34.2
PHP Version
8.2.12
Database Driver & Version
MySQL
Description
When running php artisan test, each test is now taking significantly longer to run since updating from v10.33.0 to v10.34.2. I'm using assertJsonFragment in my test cases.
The screenshots attached highlight the differences where all I did was both upgrade & downgrade. I have in excess of 50 tests, and here's the comparison of test times between framework versions:

v10.33.0 = takes less than 60 seconds
v10.34.2 = takes 155 seconds to run

I suspect that this change might be responsible for the performance bottle neck.
Steps To Reproduce

Create a Feature test that asserts JSON fragment

/**
 * A basic feature test example.
 */
public function test_user_notifications_endpoint_returns_correct_response_when_deleting(): void
{
    $userId = $this->user->id;

    $this->loginAs($this->user);

    $response = $this->delete("/api/account/$userId/notifications/99999");

    $response->assertStatus(404)
                ->assertJsonFragment([
                'metadata' => [
                    'message' => 'Notification not found or already marked as read.'
                ]
            ]);
}

Run php artisan test
Observe the performance outcome of both

Framework v10.33.0

Framework v10.34.2

Here's my composer.json file:
{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^8.1",
        "deployer/deployer": "7.3.3",
        "doctrine/dbal": "^3.6",
        "guzzlehttp/guzzle": "^7.2",
        "lab404/laravel-impersonate": "1.7.4",
        "laravel-notification-channels/webhook": "2.5.0",
        "laravel/fortify": "1.19.0",
        "laravel/framework": "10.34.2",
        "laravel/horizon": "5.21.4",
        "laravel/sanctum": "3.3.2",
        "laravel/slack-notification-channel": "3.1.0",
        "laravel/telescope": "4.17.2",
        "laravel/tinker": "^2.8",
        "mongodb/laravel-mongodb": "4.0.2",
        "mtownsend/collection-xml": "^1.7",
        "mtownsend/request-xml": "2.3.0",
        "mtownsend/response-xml": "2.2.0",
        "nesbot/carbon": "2.71.*",
        "php-http/message-factory": "^1.1",
        "propaganistas/laravel-disposable-email": "2.2.15",
        "propaganistas/laravel-phone": "5.0.3",
        "psr/http-factory-implementation": "*",
        "rappasoft/laravel-authentication-log": "3.0.0",
        "rinvex/countries": "9.0.1",
        "sentry/sentry-laravel": "4.1.0",
        "spatie/cpu-load-health-check": "1.0.4",
        "spatie/laravel-health": "1.23.7",
        "spatie/laravel-permission": "6.1.0",
        "spatie/laravel-schedule-monitor": "3.4.1",
        "square1/laravel-collection-rolling-average": "1.0.0",
        "staudenmeir/laravel-adjacency-list": "1.13.11",
        "thomasjohnkane/snooze": "2.3.1",
        "torann/geoip": "3.0.5",
        "yoeriboven/laravel-log-db": "1.1.1"
    },
    "require-dev": {
        "fakerphp/faker": "^1.9.1",
        "laravel/pint": "^1.0",
        "phpspec/prophecy": "~1.0",
        "laravel/sail": "1.26.2",
        "mockery/mockery": "^1.4.4",
        "nunomaduro/collision": "^7.0",
        "php-mock/php-mock": "^2.4",
        "phpunit/phpunit": "^10.0",
        "spatie/laravel-ignition": "^2.0"
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/"
        },
        "files": [
            "app/helpers.php"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-update-cmd": [
            "@php artisan vendor:publish --tag=laravel-assets --ansi --force"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true,
        "allow-plugins": {
            "pestphp/pest-plugin": true,
            "php-http/discovery": true
        }
    },
    "minimum-stability": "stable",
    "prefer-stable": true
}

@nshiro since you sent in that PR, what are your thoughts here?

@sts-ryan-holton can you verify if your tests using UserFactory and share the content of UserFactory?

UserFactory looks like this:
<?php

namespace Database\Factories;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;

class UserFactory extends Factory
{
    /**
     * Define the model's default state.
     */
    public function definition(): array
    {
        return [
            'timezone' => 'UTC',
            'first_name' => $this->faker->firstName(),
            'last_name' => $this->faker->lastName(),
            'email' => $this->faker->unique()->safeEmail(),
            'email_verified_at' => Carbon::now(),
            'password' => Hash::make('password', [
                'rounds' => 5, // only for dummy users, do not use this value for production.
            ]),
            'country_code' => 'GB',
            'phone_number' => '+447900000000',
            'prefers_time_sensitive_notifications' => false,
            'notify_on_days' => [1, 2, 3, 4, 5, 6, 7],
            'notify_time_slot' => 'anytime',
            'datetime_format' => 'HH:mm, MMM Do YYYY',
            'on_holiday_until' => null
        ];
    }

    /**
     * Indicate that the model's email address should be unverified.
     */
    public function unverified(): Factory
    {
        return $this->state(function (array $attributes) {
            return [
                'email_verified_at' => null,
            ];
        });
    }
}

No difference setting hash to 1 btw.

@sts-ryan-holton could you pinpoint the exact version where things went slow for you?

@driesvints Sure thing, I'll try my best :)
Basically, I update my project once a week with dependencies. Currently, on v10.34.2 with the composer.json file in the description and running php artisan test every single test is super slow. If I just update:
From:
"laravel/framework": "10.34.2"

To (downgrade):
"laravel/framework": "10.33.0"

Without changing anything else in my project and running composer update (only Laravel framework gets downgraded), then the tests in my project instantly get faster. Upgrading to 10.34.2 again slows it back down, no other changes in code.
Additionally, I even tried individual versions of the framework since that release, here's my results:
prior to v10.33.0 - fast sub minute)
v10.33.0 - fast (sub minute)
v10.34.0 - slow (150+ seconds)
v10.34.1 - slow (150+ seconds)
v10.34.2 - slow (150+ seconds)

@sts-ryan-holton have you tried simply reverting this change in your vendor directory and seeing if it helps?
https://github.com/laravel/framework/pull/49160

It should be one of these PR's then. Would appreciate any help in figuring out which one it is: https://github.com/laravel/framework/releases/tag/v10.34.0

I'll take a look now

@sts-ryan-holton it may be the transaction related PR - are you able to create a test repo for us to clone down?

@taylorotwell Is there a way I can revert that change locally to see if it is causing the problem? Creating a test repo might take longer than reverting that change and reverting the files?
If I revert those files or parts of them that might pinpoint the change?

@sts-ryan-holton We still need to be able to replicate the issue and determine what can be done to improve the code. The only way to be able to do that is by having a reproducible code.
v10.34.0: https://github.com/laravel/framework/actions/runs/7020631916/job/19100818953
v10.33.0: https://github.com/laravel/framework/actions/runs/6945488635/job/18894960822
There no significant time increased in Framework own tests to suggest there is an issue with Transaction related changes.

@sts-ryan-holton maybe - you would probably need to revert ManagesTransaction, DatabaseTransactionManager, and maybe Connection to make it happen.
Agree with @crynobone a repo is likely still necessary for us to actually fix it even if that is causing the issue.

Not much to add in way of a solution, but I've been noticing an increase in parallel worker crashes in our app pipelines since upgrading packages on Monday.
Didn't look into it too deeply, as I figured it may have just been an environment issue on our end.

10.33.0
Time: 01:08.550, Memory: 325.50 MB

OK, but there were issues!
Tests: 9199, Assertions: 27320, Deprecations: 1, Skipped: 238.

10.34.0
 Time: 01:10.584, Memory: 327.50 MB

Tests: 9228, Assertions: 27393, Deprecations: 1, Skipped: 240.

Compared version using PHP 8.2 (prefer stable), the closest to your reported issue with the latest version having 29 more tests and only 2 extra seconds is minimal.

I'm simply comparing the difference in times from the links you'd sent above:
10.33.0

succeeded 2 weeks ago in 3m 16s

10.34.0

succeeded last week in 4m 14s

An entire minute increase in changing the version of the framework. Which, arguably, based on the number of tests shown in your most recent screenshot would imply that if quite a few tests were added and the time doesn't go up by that much that a minute increase is quite significant

@sts-ryan-holton that time difference includes setting up the container, running composer install, and other requirements, you should instead just look at PHPUnit execution times.
We can only move forward with reproducible code. We have reviewed our other internal application and are unable to replicate this issue, and this doesn't seem to be a widespread issue as others would already submit similar issues.

I agree it's tough for us to move this issue forward without a repo we can clone down to reproduce the issue. Happy to look if something like that can be produced. 👍

@sts-ryan-holton I wonder if there maybe isn't another shared package in both of our applications that is causing this to happen? 🤔

I've got a list of dependencies in my original description :)

In your test class that sees the big performance difference, what base test class are you extending, which traits are applied to the class? Is there any other setup code with those could be relevant here?

I noticed my tests running slowly recently. It looks like there is an issue somewhere, 10.33.0 tests:
Tests:    2 risky, 96 passed (307 assertions)
Duration: 10.73s
10.34.0
Tests:    2 risky, 96 passed (307 assertions)
Duration: 24.47s
After updating to the latest:
Tests:    2 risky, 96 passed (307 assertions)
Duration: 29.93s
However, I've isolated why my tests are running slow, if I comment out this sqliteCreateFunction from my test setup then they run fast again.
            DB::connection()->getPdo()->sqliteCreateFunction(
                'CONVERT_TZ',
                function ($value, $fromTimezone, $toTimezone) {
                    return Carbon::createFromFormat('Y-m-d H:i:s', $value, $fromTimezone)->setTimezone($toTimezone);
                }
            );

Not spotted the issue in the framework that's causing this.

Larwvel 10.34 and on certainly has slowed tests down significantly. We've had to factor this additional time into our build processes

I back @sts-ryan-holton. 10.34 introduced a significant delay of aprox 100ms per test. @EPGDigital-MW sqliteCreateFunction was my initial consideration but after I started timing everything I've excluded it. I have nearly 20 sqliteCreateFunctions in my tests and it takes about 5-10 ms to run.
Digging around to find discrepancies in the process, I started dumping raw migrations SQLs in files and compare between 10.33 and 10.44.
10.44 run the following two during migrations:
select 1 from pragma_compile_options where compile_options = 'ENABLE_DBSTAT_VTAB') as enabled;
select m.tbl_name as name, sum(s.pgsize) as size from sqlite_master as m join dbstat as s on s.name = m.name where m.type in ('table', 'index') and m.tbl_name not like 'sqlite_%' group by m.tbl_name order by m.tbl_name;
Digging around a little bit more, I found that these have been introduced because of the change in src/Illuminate/Database/Schema/Builder.php
Commit:
https://github.com/laravel/framework/commit/50807dbcb79c863d5cb5da52de929ee9ca508d33#diff-1a147b8174f4809f7471525e9d676e831176efdbeb69af8af6e95c1a72aef962R162
This foreach calls getTables: https://github.com/laravel/framework/commit/50807dbcb79c863d5cb5da52de929ee9ca508d33#diff-5ceeb999b82b50cc8a3ec3e64b5a98af805fde210c2c58d407706965d109d38d
and that calls compileDbstatExists and compileTables and runs these two queries:
https://github.com/laravel/framework/commit/50807dbcb79c863d5cb5da52de929ee9ca508d33#diff-7cf2f940b724463282b1dbae24464cb3a7c7c0864d40b4c3706eb99f65994d2cR46
Reverting the code in src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php from:
        foreach ($this->getTables() as $value) {
            if (strtolower($table) === strtolower($value['name'])) {
                return true;
            }
        }

To:
        return count($this->connection->selectFromWriteConnection(
                $this->grammar->compileTableExists(), [$table]
            )) > 0;

brings the testing speeds back to normal.
Digging a bit more (sorry I know 😢) I found that this:
https://github.com/laravel/framework/commit/94634fe7127449ba438b6fd62cbcc31fa598e603
is what actually causing the delay.
(i.e. the select 1 from pragma_compile_options where compile_options = 'ENABLE_DBSTAT_VTAB') as enabled; query)
\Illuminate\Database\Schema\SQLiteBuilder::getTables is being called by \Illuminate\Database\Schema\Builder::hasTable and every time hasTable is being called, effectively trying to get a true/false answer, we delay the response because we calculate the table size (something completely useless for our yes or no question).
This is my suggestion:
https://github.com/laravel/framework/pull/50869
cc @taylorotwell

Tests have been super slow since updating and have been since. It's been 4 months+ now, yet still slow.

Have you tried LazilyRefreshDatabase (PR #38861) instead of RefreshDatabase?

Have you tried LazilyRefreshDatabase (PR #38861) instead of RefreshDatabase?
RefreshDatabase calls migrate:fresh command that uses hasTable() internally. LazilyRefreshDatabase does the same but only when the database is actually required in the test.

Yes I'm using it for some time now. My test suite is made of nearly 10k tests and the 100ms delay adds about 15mins to the total CI pipeline.
As I mentioned in my latest PR, hasTable returns a Boolean and the table size is irrelevant, especially when it adds unnecessary overhead. Unless I missed something through the flow? Apologies if I did.

@hafezdivandari I'll jump back in an just mention, that although there might be alternative traits and features to improve the performance, but fundamentally, when the issue was initially open, simply upgrading without implementing said features caused a significant performance impact.

@sts-ryan-holton 10.48.5 went out an hour ago. I'm keen to know if my fix has sorted out your issue. It worked for me.

@apspan I can confirm after upgrading to this version, that prior to upgrading would take 156 seconds. After upgrading it took just 38 seconds, so yes, that change worked.
Worth also noting, I had a few tests on my most recent Laravel 11 project which has also become a few seconds faster.
Honestly can't believe that this bug has been around since December 2023, but glad it's resolved now 👍

Hi, I have the same problem while upgrading a project from laravel v10.46.0 to v11.3.1.
Same tests, laravel v10.46.0: 60 seconds
Same tests, laravel v11.3.1: 350 seconds
I use MySQL as my database, so, maybe, it's a little different from this issue

authors: EPGDigital-MW apspan cosmastech crynobone danieletulone devoidfury driesvints hafezdivandari sts-ryan-holton taylorotwell


text:
[5.0] Validator each() not build nested rules correctly

Hi guys,
during validation of arrays with Validator->each()I encountered a little bug during the build nested keys routine.
https://github.com/laravel/framework/blob/5.0/src/Illuminate/Validation/Validator.php#L266
My input
'pairs' => [
    ['foo' => 'startOfLine', 'value' => '']
]

My validate each method:
$v = \Validator::make($input, ['pairs' => 'required|array']);

$v->each('pairs', [
    'keyword' => 'required',
    'value' => 'required'
]);

Generated rules are:
[
    'pairs' => ['required', 'array'],
    'pairs.0' => ['required', 'required']
]

In my opinion generated rules should are:
[
    'pairs' => ['required', 'array'],
    'pairs.0.keyword' => ['required']
    'pairs.0.value' => ['required']
]

My fix for this would be to use this:
foreach ($rules as $ruleKey => $ruleValue)
{
    $this->mergeRules("$attribute.$dataKey.$ruleKey", $ruleValue);
}

instead of this:
foreach ($rules as $ruleValue)
{
    $this->mergeRules("$attribute.$dataKey", $ruleValue);
}

If I should provide further information, add a failing test, or create a pull request, please let me know.
Best regards,
Eric

We're open to pull requests.

Wouldn't that break the first example?

Yea. The PR breaks a test. Sorry for that. Didn't thought about that before.
But in conclusion both behaviors seems strange to me.
I will have a further look tomorrow.

authors: GrahamCampbell erickubenka taylorotwell


text:
[5.1] Jobs fail to run when a dependent model is deleted

If a Model is serialized in let's say Job A, and it is deleted in Job B before this job can run, it throws an exception during the __wakeup() call, throwing it back in queue infinitely.
The problems with the current Job system in this case:

You're unable to catch any Exceptions during the __wakeup() or deserialization phase
The serialization of the model is called with findOrFail()

https://github.com/laravel/framework/blob/5.1/src/Illuminate/Queue/SerializesModels.php#L65
[2015-06-20 18:03:22] production.ERROR: exception 'Illuminate\Database\Eloquent\ModelNotFoundException' with message 'No query results for model [KikFinder\Submission].' in /var/www/kikfinder.com/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:127
Stack trace:
#0 [internal function]: Illuminate\Database\Eloquent\Builder->findOrFail('127')
#1 /.../bootstrap/cache/compiled.php(11013): call_user_func_array(Array, Array)
#2 /.../vendor/laravel/framework/src/Illuminate/Queue/SerializesModels.php(65): Illuminate\Database\Eloquent\Model->__call('findOrFail', Array)
#3 /.../vendor/laravel/framework/src/Illuminate/Queue/SerializesModels.php(65): KikFinder\Submission->findOrFail('127')
#4 /.../vendor/laravel/framework/src/Illuminate/Queue/SerializesModels.php(40): KikFinder\Jobs\Admin\DeleteSubmission->getRestoredPropertyValue(Object(Illuminate\Contracts\Database\ModelIdentifier))
#5 [internal function]: KikFinder\Jobs\Admin\DeleteSubmission->__wakeup()
#6 /.../vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(38): unserialize('O:37:"KikFinder...')

I don't see what the issue is. They only go back in the queue if they haven't been retried enough times?

Not throwing an exception here would be incorrect. We need to indicate that waking up the object has failed.

throwing it back in queue infinitely.

Looks like a configuration issue on your side to me?

I still believe that there should be a way to either handle the exception, or to pass it as null.

Since it will continue to always be null, retrying isn't going to do anything in this case.

or to pass it as null.

We definitely don't want that. That's why it was changed to findOrFail.

retrying isn't going to do anything in this case.

That's not our logic though. You configure the retrys.

@GrahamCampbell @EvanDarwin This is actually an issue with you're dealing with Soft Deletes. If you try to pass a soft-deleted model into a queued job, it will fail because findOrFail() won't find it - but the model is a perfectly valid model and is still usable.
For example, we have a common class that handles marking models as deleted on the form submission. It then fires a ModelWasDeleted event. I am trying to set up a listener for that event that will queue a job with the deleted event to clean up extra data in the background - but it's failing because I am passing the deleted model into it.
A simple work-around is to pass in the ID, rather than the model itself. However, this breaks our usual pattern and the change in behaviour when using SerializesModels isn't really expected.

@valorin the workaround I used was to override the getRestoredPropertyValue() function and including the ::withTrashed() method when finding the object.

Or you could also do something similar to this in the case that the object is actually permanently deleted, and anyone else looking at this issue:
    /**
     * Override this to catch in the case that the model is already deleted
     */
    protected function getRestoredPropertyValue($value)
    {
        if($value instanceof ModelIdentifier) {
          $model = (new $value->class)->find($value->id);
          return ($model) ? $model : null;
        } else {
          return $value;
        }
    }

Or remove SerializeModels for deleted resources?

Hey thanks @EvanDarwin for that snippet, it was really helpful. This would be really helpful for large transactions in some scenarios.

@EvanDarwin I've tried override getRestoredPropertyValue this generate an error :
[2015-10-08 10:47:57] local.ERROR: exception 'ErrorException' with message 'Undefined property: Illuminate\Contracts\Database\ModelIdentifier::$user'

The model returned is empty nut its not deleted :'(

Thanks @EvanDarwin

@EvanDarwin where are you overwriting that method? Does it get placed inside the job class? or on the model? or were you referring to something else?
I have jobs that run and work with softDeleted data but it is failing because it can not findOrFail with trashed on the job. I would like to have certain jobs include trashed items.
What are your thoughts?

@johnpaulmedina I no longer use Laravel but I believe the code went into the actual Job class.

I made a new trait and overrode the method:
use SerializesModels, SerialisesDeletedModels {
    SerialisesDeletedModels::getRestoredPropertyValue insteadof SerializesModels;
}

use Illuminate\Contracts\Database\ModelIdentifier;

trait SerialisesDeletedModels
{
    protected function getRestoredPropertyValue($value)
    {
        if ($value instanceof ModelIdentifier) {
            $model = new $value->class;

            if (method_exists($model, 'withTrashed')) {
                return $model->withTrashed()->findOrFail($value->id);
            }

            return $model->findOrFail($value->id);
        } else {
            return $value;
        }
    }
}

Thanks @valorin for the example. This works for me, while running Laravel 5.2:

namespace App\Traits;

use Illuminate\Contracts\Database\ModelIdentifier;

/**
 * Class SerialisesDeletedModels
 * @see https://github.com/laravel/framework/issues/9347#issuecomment-165647596
 */
trait SerialisesDeletedModels
{
    /**
     * @param $value
     * @return mixed
     */
    protected function getRestoredPropertyValue($value)
    {
        if (!$value instanceof ModelIdentifier) {
            return $value;
        }

        if (is_array($value->id)) {
            return $this->restoreCollection($value);
        }

        $instance = new $value->class;
        $query = $instance->newQuery()->useWritePdo();

        if (property_exists($instance, 'forceDeleting')) {
            return $query->withTrashed()->find($value->id);
        }

        return $query->findOrFail($value->id);
    }
}

@emielmolenaar is there any reason you used find on the withTrashed query, but findOrFail on the final query?
    if (property_exists($instance, 'forceDeleting')) {
        return $query->withTrashed()->find($value->id);
    }

    return $query->findOrFail($value->id);

I guess because findOrFail will throw an exception on models that have been soft-deleted. The withTrashed()->find($value->id) "fixes" this by including soft-deleted models.

Right, but could you not have done withTrashed()->findOrFail to throw an exception if the model truly does not exist (not even in the 'trashed' part of the collection)? Just want to make sure I understand!

Good one. I guess I could have used withTrashed()->findOrFail(), but in this case I only used soft-deleting models so a record would always exist.
If you use a mix of soft-delete and "hard-delete" models, then withTrashed()->findOrFail() instead of withTrashed()->find() might be a good option; but you should do some tests to verify the wanted behaviour.

@emielmolenaar I don't believe that to be true, there's are plenty of perfectly valid use cases for retrieving a soft-deleted model such as offloading analysis of the model to the task queue. (An example would be analyzing a deleted Submission, etc.)

When you use soft-delete models and a job gets queued with a non-existing (i.e. no database record) soft-deleted model in it then there is a serious problem: that is a situation that theoretically should not exist :smile:

@emielmolenaar: You've obviously never worked with an app that throws jobs into the queue which could be delayed for processing by minutes or even hours. In one of my apps, it was a common occurrence for a user to create or update a record (which triggers a queued job), and then delete the record. If my queue was flooded (which is common, and the reason I'm using queues), then it's definitely possible the queue job tries to revive a record that has since been deleted.
It's got nothing to do with "a serious problem" in the app - but timing. Queued jobs can be delayed, and records can be deleted at any time - especially when users are involved. You need to handle all cases.

@emielmolenaar sorry, ignore my last. I miss-read your comment.

authors: EvanDarwin GrahamCampbell InstanceOfMichael Reeslo crabmusket emielmolenaar johnpaulmedina kaiserlos leitom valorin


text:
[5.3] TokenGuard fix for when invalid token supplied and no user retrieved

With non-guarded api routes sometimes we want to allow guest access but also access the user if a token was supplied. For example when allowing guest and user posts to a service. When calling Auth::guard('api')->user() it is not possible to differentiate between guest access and an invalid token. The provided fix will throw an authentication exception in this particular case, this allows the user to recognise their token is invalid and fix that issue (e.g. by logging in again and retrieving a new token) rather than the site assuming they are a guest. Thanks!

Maybe 401 should be the code for this exception since credentials were supplied but were invalid.

An alternative would be to make getTokenForRequest method public, then we could check if there was a token but the user is null then we know it was an invalid token.

Closed because feel that making getTokenForRequest is a better option so will do a PR for that instead.


text:
Update message when creating a migration

Recently I try to create a migration and it keeps saying to me that A {$class} migration already exists. but there was no migration with that $class name. Actually, it was a Seeder.
I know, the message isn't consistent, but, as migrations and seeder aren't namespaces, this PR makes sense?

Maybe it'd be better to namespace them?

@m1guelpf But then would be necessary to create a bug like Namespace migrations and factories and add this to a future version of Laravel, because would cause big changes :thinking:

@gabriel-caruso I can see how namespacing the seeders could cause some problems, but I don't think namespacing migrations could cause any. Aslo, if we move the database/ folder to PSR, we don't need to load it with composer every time Laravel makes a request...


text:
Make Password Rest Mail Translatable

if password reset email get translatable, there is no need make new notification and overwrite the
sendPasswordResetNotification() in  User Model
PR for translation files sent

This is already customizable I believe.

who i can translate password reset text and make email multilingual without
make new notification and overwriting sendPasswordResetNotification()  in User model ?

authors: cracki taylorotwell


text:
[8.x] Add command to clean batches table

Provides a queue:flush-batch command for cleaning the job_batches table added in 8.x.
>>> php artisan queue:flush-batch
199 entries deleted.

Heavily inspired by the telescope:prune command this change is almost an exact copy of that.
https://github.com/laravel/telescope/blob/master/src/Console/PruneCommand.php
It has an --hours optional argument that defaults to 24 and it uses the finished_at column to do the date comparison.
Similarly to telescope it can easily be put into the scheduler:
$schedule->command('queue:flush-batch --hours=48')->daily();

I used flush to be consistent with the existing queue:flush command but I can change it to prune if preferred.
None of the queue commands currently have tests so I haven't added any for this one.
If you want me to add tests please do let me know.

I'm not sure if "flush-batch" is the right word? That makes me think all of the table's records will be deleted when really it's just pruning existing ones.

As I mentioned in the OP prune is the correct term but its not something that has been used anywhere else in core. If you want I can change class names and command signature to use prune instead. The new command would be queue:prune-batch ?

I would likely call it something like queue:prune-batches

Pushed change to queue:prune-batches as discussed.


text:
[9.x] JSON Session Option

This pull requests allows developers to choose to serialize session data in storage using PHP or JSON. Over the years, several people have expressed concerns with deserializing sessions using PHP's unserialize function, as this could lead to security problems (including remote code execution) if the application's encryption key is leaked.
However, all known ways to exploit this require the attacker to know the application's encryption key, which if known, could already be used to craft authenticated cookies for the application, etc. Nevertheless, offering this an option to those who would prefer to use JSON to serialize sessions in storage.

This is very interesting, both from a security perspective and since it makes the payload around 10–15 % smaller (measured both on a clean install and on a larger project).
I am running an app which uses the cookie driver and I am probably going to switch to the json setting if/when merged. However I am going to have to do the migration transparently, meaning that no session data should be lost. That is achievable by overriding readFromHandler() to fallback to unserialize in case json_decode returns null. If/when this is merged and I can successfully verify that transparent migration, I might publish a tiny package, or just a gist, for that code (which only needs to run > one session lifetime). It could of course also be solved with a php-to-json setting in the core, but that is perhaps unnecessary for the narrow use case.

authors: Krisell taylorotwell


text:
[9.x] Deep copy functionality on Collection and LazyCollection

This PR adds the functionality of creating a deep copy of a Collection instance. This means that new references are created for the objects inside the Collection. A deep copy is useful when the Collection contains non built-in types, since clone will only make new references of built-int types (shallow copy). So for example here:
$testObject = new TestObject();
$testObject->quantity = 1;
$collection = new Collection(array($testObject));
$clonedCollection = clone $collection;
$clonedCollection->changeQuantity(2);

class TestObject
{
     public int $quantity;
}

What happens is that both the quantity of the $clonedCollection and the $collection instances have been changed to 2, as they share the same reference of $testObject. To solve this, you can map over the instances yourself and return a cloned version:
$collection->map(function (TestObject $testObject)
{
      return clone $testObject;
});

But this will not work if TestObject has instances of non built-in types, then you need to loop through them too. So therefore, a better solution in my opinion is to have a deepCopy function on a Collection instance, such that the end user does not need to loop through the nested objects and clone them. A deep copy will make sure that new references are made for every instance, even for non built-in types and works for nested objects. I did not implement the deep copy logic myself, but I use the library from myclabs/deep-copy.
The end user can then use the following:
$deepCopiedCollection = $collection->deepCopy();

Let me know what you think! Also, this feature was proposed in a closed issue (https://github.com/laravel/framework/issues/15286). But no new PR was ever made to add this feature.

One can install myclabs/deep-copy package in their project and deep copy the objects.

Thanks for your pull request to Laravel!
Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.
If possible, please consider releasing your code as a package so that the community can still take advantage of your contributions!
If you feel absolutely certain that this code corrects a bug in the framework, please "@" mention me in a follow-up comment with further explanation so that GitHub will send me a notification of your response.

authors: ankurk91 fmeccanici taylorotwell


text:
Adds a shortForm parameter to forHumans method of Number helper to output 1 M instead of 1 million

Adds a optional parameter to the forHumans method of Illuminate\Support\Number class. When this parameter
Currently it formats the bug number as 1 thousand, 1 million , 1 Billion . This PR adds a optional parameter shortForm, when set to true, this method will format the number as 1 M, 1 B , 1 T and so on.
This does not break current implementation because , current value is provided as default. 😊

Thanks for your pull request to Laravel!
Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.
If possible, please consider releasing your code as a package so that the community can still take advantage of your contributions!
If you feel absolutely certain that this code corrects a bug in the framework, please "@" mention me in a follow-up comment with further explanation so that GitHub will send me a notification of your response.

@taylorotwell , feels strange that i made this PR to to get the exact behaviour described here 😕 only few days ago.
Only to be told framework does not want this right now. And my implementation is also pretty close.


text:
Add CommandErrored to listen the ConsoleErrorEvent

Sometimes, we need to take additional action when a command fails, such as reporting it to our monitoring platform. However, currently, the CommandFinishedEvent is triggered whether the command is successful or not. Although the CommandFinishedEvent contains the exit code, we want to capture the reason for the command failure. Therefore, I created a CommandErroredEvent.

Simply throwing an exception is not working?

Simply throwing an exception is not working?

This is what we do now, using a global handler to report exceptions, but I think it is not suitable for commands.

We can listen to the CommandStartingEvent and send a message to the monitoring system saying ‘the xxx command is running’ when the command starts.
We can listen to the CommandFinishedEvent and send a message to the monitoring system saying ‘the xxx command finished successfully’ when the command finishes with an exit code of 0.
The challenge is how to inform the monitoring system when a command fails with an exception. If we report to the monitoring system in the global handler, the CommandFinishedEvent will still be triggered, forcing us to report to the monitoring system again. If we only rely on the exit code to inform the monitoring system of the command’s execution status, we will lose the exception information, and the exit code can be reset.

In that case, I would go with CommandFailed. Much nicer. But I also would have gone with a try/catch if it is not for commands from third party or framework...

Thanks for your pull request to Laravel!
Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.
If applicable, please consider releasing your code as a package so that the community can still take advantage of your contributions!

@taylorotwell Thank you for the information. It seems you would like to reconsider whether it is reasonable to handle the Symfony console event there.

authors: henzeb taylorotwell yankewei


text:
[11.x] feat: add Str::doesntContain() method and supporting tests

Hi :wave:,
In my Laravel projects where I utilise the Str::contains() method, I often find that I need the inverse functionality of this. Whilst I can just prepend with ! to get the inverse, readability in the method name can make better sense.
This PR introduces a new Str::doesntContain() method that internally utilises the same functionality as contains except does the inversing for the end user whilst retaining a readable function name! Simple but effective!

Related: #40396, #52969

Related: #40396, #52969

Worth another stab! :)

authors: NickSdot sts-ryan-holton


text:
fix change column in Grammar.php

Bug found changing a float column to decimal with a migration
php artisan migrate returns
'Doctrine\DBAL\DBALException' with message 'Unknown column type "decimal(8, 2)"
because $this->getType($fluent) returns decimal(8,2).
$fluent['type'] should be used in order to call the proper Doctrine getType function to work

Please only send to one branch.

authors: GrahamCampbell angelomaragna


text:
[5.0] FormRequest Database Connection

This enables the "unique" validation rule to check against a table on a database that is not the default connection.
Resubmitted due to rebase mistake.

Just added the ability that @xyxu was looking for. Can now add an optional database in the rule itself (i.e. unique:database.users,...). Let me know if you want an additional assertion for the optional database to be added to testValidateUnique() in ValidationValidatorTest

Isn't this a breaking change to just change the order of the validator parameters for unique?

Nvm I see you are using dot syntax.

Let me know what you'd prefer and I'll resubmit, if need be.

Added connection support to unique rule in 5.1.

authors: taylorotwell wells


text:
[5.1] Add Request::wants()

Determines whether the current requests accepts a given content type based on content negotiation.
This would allow us to serve different content-types for same endpoints based on the Accept header.
switch ($request->wants(['html', 'json']) {
   case 'html' :
      return view('users.index', $users);
   case 'json' :
      return $users->toJson();
   default :
      throw new NotSupportedException();
}

Signed-off-by: crynobone crynobone@gmail.com

Wrong branch
There's duplicated code here.

As I said already. I'm going to work on something much better were we actually get a list back in prioritized order.

I also disagree with not provided the mime type.

Actually, in retrospect, this way of doing it actually is a good idea @crynobone. Could you resend this based on 5.1 after my other changes are finalised so we don't have code duplication.

Would like to know where we can reduce the code duplication so it can be included in the new PR.

I'll get back to you once my PR that introduces that reusable method is through. :)

authors: GrahamCampbell crynobone


text:
Add FeatureRetrieve & FeatureResolve events

We at Sentry would be interested in having events fired before a feature gets retrieved or resolved, so we can properly wrap it into a span or add breadcrumbs.
Is this something you would be open to add? If so, I'm happy to provide a PR.

Hey @cleptric!
We already have a handful of events available for this. I've outlined the relevant events below in hopes that it might help. If you feel that additional are needed, please feel free to attempt a PR with your needs.
Laravel\Pennant\FeatureResolved
This event is fired whenever a feature is resolved against a scope, i.e. the feature definition closure is run of the feature class's resolve method is run.
If a feature is checked 10 times within a single request this event may fire 0 - 1 times.
Laravel\Pennant\UnexpectedNullScopeEncountered
This event is fired when a feature is being resolved when the feature closure of resolve method does not accept null and the scope being checked is null.
This event is fired while a feature is being resolved.
Laravel\Pennant\FeatureRetrieved
This event is fired whenever a feature is retrieved. If a feature is checked 10 times within a request this event is fired 10 times.
Laravel\Pennant\UnknownFeatureResolved
This event is fired when a unknonwn feature is being resolved, i.e. if I try and check a feature that doesn't exist Feature::active('asdfasdf')

We are mainly interested in adding events that are fired before feature retrieval. Similar to RequestSending and ResponseReceived for the HTTP client.

authors: cleptric timacdonald

repo: laravel/pennant